Change the style, attribute "display", of a canvas in Javascript

-1

I have a Javascript function that takes an empty canvas and fills it. Only, as at first I do not want to display the canvas, I set the style of it, in the display attribute as "none". Now, I change the display to block (at runtime). How could I do this in Javascript?

This is the canvas in my html:

<canvas class="canvasCentral" id="bordas" width="400" height="500">

    </canvas>

The style applied to the canvas is the canvasCentral class of a css file linked to my html:

.canvasCentral{
        position:absolute;
        top:50%;
        left:50%;
        transform:translate(-50%,-50%);
        border:3px solid #D8D8D8;
        border-radius: 20px;
        display:none

    }

How can I, in Javascript, at runtime change the canvas display to block?

    
asked by anonymous 09.06.2018 / 16:54

1 answer

1

You can pick up the id

document.getElementById('bordas').style.display = "block";

Or by the class (if you want to change for all elements that use this class)

var elementos = document.getElementsByClassName("canvasCentral");
elementos.forEach(alteraDisplay)

function alteraDisplay(item, index) {
    item.style.display = "block";
}
    
09.06.2018 / 17:23