Search code examples
javascripthtmlcssbulma

How to create Bulma button element rather than HTML <a>, using JS


This is my js script. It only creates an anchor tag with text rather than a bulma button.

elementos.forEach(function(value,index){
    var button = document.createElement("a");
    button.class = "button is-primary is-rounded";
    button.innerHTML = "Element " + (index +1)+ ": " + value
    container.appendChild(button);
})

Solution

  • The problem is in your syntax.

    This is the correct way to add a class to an element with Javascript:

    button.classList.add("button is-primary is-rounded")