Add javascript variable in CSS class

0

I need to insert into this following CSS class:

    .bola {
        width: 50px;
        height: 50px;
        border-radius: 25px;
        position: absolute;
    }

the variable var corBola = "#"+((1<<24)*Math.random()|0).toString(16) which generates a hexadecimal value of random color, how can I do the insert to change the color and insert the background-color attribute using this random variable?

    
asked by anonymous 23.08.2018 / 19:36

1 answer

2

Javascript:

document.getElementsByClassName("bola").style.backgroundColor = corBola;

jQuery:

$('.bola').css({'background-color': corBola});
    
23.08.2018 / 19:44