简体   繁体   中英

'This' Selector in Javascript

I am dynamically creating a page (in VB) and thus have a number of elements with the same class. I need to animate these individually, not as a group. I have done this in the past with the this selector. But I can't seem to get it functioning now.

$(".img").on("mouseover", function () {
  $(".img").animate({
    right: '75px',
    speed: 'fast'
  });
});

Replace the string selector with this

$(".img").on("mouseover", function () {
  $(this).animate({
    right: '75px',
    speed: 'fast'
  });
});

Inside the handler, this will be the specific .img instance in which the mouse hovered

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM