Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a button background with javascript?

I have a button having the following CSS background rule applied:

background-image:url('/images/button_1_normal.png');

I would like to change the button's background with JavaScript. I tried the following but it didn't work.

document.getElementById(step2).style.backgroundImage = "url('images/button_1_active.png') no-repeat";

What is the problem? Thank you

like image 593
Julia Avatar asked Aug 23 '26 11:08

Julia


1 Answers

no-repeat is invalid. Only the URL part is a valid value for the background image property.

Either remove that or change your assignment to background:

document.getElementById(step2)
    .style.background="url('images/button_1_active.png') no-repeat";
like image 157
Kevin Boucher Avatar answered Aug 26 '26 01:08

Kevin Boucher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!