CSS Search Element at JS

0

Well, I'm now starting programming in HTML5 + JavaScript + CSS and I have a question that I suppose is basic but I can not find an answer. I created an HTML5 canvas and since I was not able to add buttons (created in HTML) on the canvas, I decided to make my own JavaScript buttons. My question is: I wanted to customize the button and as I created it in JS, is there any way for CSS to fetch the button from JS instead of HTML?

    
asked by anonymous 22.03.2016 / 19:25

1 answer

0

You can add the entire button design to a CSS Class and when you add the button in JS you add it to the Class.

CSS:

.btn {
    width: 100px;
    height: 30px;
    text-align: center;
}

JS:

var newNode = document.createElement('button');
newNode.className = 'btn';
newNode.innerHTML = 'Botão 1';
    
22.03.2016 / 19:43