Add javascript variable in CSS class

Asked

Viewed 149 times

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 random color value, as I can do the insertion to change the color and insert the background-color attribute using this random variable?

1 answer

2


Javascript:

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

jQuery:

$('.bola').css({'background-color': corBola});

Browser other questions tagged

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