Add style using javascript?


Its possible to add style using javascript?
I have this on the header:

  #canvas-gradient {
    position: absolute;
    display: block;
    width: 100%;
    height: 100%;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;

But I want to know if its possible to add that style using javascript.


(Note: This will only work for one element, because only one element can have an ID.)


Yes, you can add the style via JavaScript instead. It's just not as convenient as doing it with CSS.

var el = document.querySelector("#canvas-gradient"); = "absolute"; = "block";
... = "0";


Thanks both! Worked!