samedi 20 août 2016

Pass image id to JQuery by clicking on the image

I'm animating images using JQuery. I'm using a button to activate the animation.

Here is my code:

$(document).ready(function(){
    $("#b1").click(function(){ // b1 is the id of button
        $(#img).animate({left: '+=20px'});   // img is the id of image
    });
});

I have five images so when I click on another image, I need to put its id into the $(#img) instead of #img. So the second image will be animated.

How do I do this?

Aucun commentaire:

Enregistrer un commentaire