Changing url of background image

Posted by João Pedro on Stack Overflow See other posts from Stack Overflow or by João Pedro
Published on 2012-06-19T21:01:54Z Indexed on 2012/06/19 21:16 UTC
Read the original article Hit count: 254

Filed under:
|
|

I'm doing this interface where I have a lot of buttons that are just a li with a background image like this

#menu ul.icons li.nove {
    background-image:url(images/edit-menu/icons/undo.png);
    background-size:contain;
    display:block;
    margin-top:29px;
}
<ul class="icons"> 
<li class="um"></li>
    <li class="dois"></li>
    <li class="tres"></li>
    <li class="quatro"></li>
    <li class="cinco"></li>
<li class="seis"></li>
    <li class="sete"></li>
    <li class="oito"></li>
    <li class="nove"></li>
    <li class="dez"></li>
</ul>

I need to create a code where I change the background image of the button when the user clicks it, to show that button its activated, I just need to change url(images/edit-menu/icons/ to url(images/edit-menu/select/ and keep the same filename. I need a way to do this dynamically so I won't have to do it for each of the 10 buttons.

Hope I was clear, thanks in advance

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery