I have a div element who's background image I want to change upon clicking the div - and then have the image change back to the original upon clicking once more. Div CSS code is below, showing its Class and ID:
.tab_box
{
width:2%;
height:20%;
position:absolute;
left:100%;
}
#tab_box1
{
background:url('cars.png') no-repeat center center;
background-size:120%;
-moz-background-size:120%;
-o-background-size:120%;
-ms-background-size:120%;
}
I have 3 other divs all using the same "class", then each has an individual "id" to give them seaprate images.
I tried the following j-query/css using toggleClass but its does not seem to work:
.one
{
width:2%;
height:20%;
background:url('mots.png') no-repeat center center;
background-size:120%;
position:absolute;
left:100%;
}
<script>
$(document).ready(function(){
$('#tab_box1').click(function() {
$('#tab_box1'').toggleClass("one")
});
});
</script>
Any suggestions as to where I am going wrong, or what method other than toggleClass could be used to switch the image to and fro?