CSS Search Element for JS

Asked

Viewed 63 times

0

Good, I am now starting HTML5 + Javascript + CSS programming and I have a question that I suppose is basic, but I can’t find an answer. I created an HTML5 canvas and since I wasn’t able to add buttons (created in HTML) to the canvas, I decided to make my own buttons in Javascript. 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 JS button instead of HTML?

  • How so created in JS? dared appendChild string? createElement? CSS always observes HTML, they are in html?

  • You can create the button by JS and link a class to it and pass attributes to the class normally, the important thing is to have a class or ID to meet with CSS

1 answer

0

You can add the entire button design to a CSS Class and when you add the JS button you add it with 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';
  • And how to insert this button in the canvas?

  • As you were inserting before?

  • I created a boot class, where I would draw a rectangle and insert text on top, but I gave up this idea because I couldn’t customize the button

Browser other questions tagged

You are not signed in. Login or sign up in order to post.