Sreeraj Chundayil
Sreeraj Chundayil

Reputation: 5859

How to avoid JQuery class selector?

I just started learning JQuery.

My code:

 $(document).ready( function(){
   $('.img').click(function(){
     $('.img').animate({
       opacity: 0.25,
       left: "+=50",
       height: "toggle"
     }, 5000, function(){                                                                                             
               // Animation complete.
   });
  })
});

here .img is an image and I am doing an animation on that. But what I want is I don't want to specify each class type like .img. All elements I have on the page(images, p,border) can go through the same animation. so I expect something like

$(this).click( function{ $(this).animate(.........

Is it possible by putting something like this we don't have to specify the exact class? I tried with this, it is not working.

Upvotes: 0

Views: 29

Answers (1)

Peter
Peter

Reputation: 447

$(".img").click(function(){
    $(this).animate( ... );
});

Upvotes: 3

Related Questions