jquery将脚本应用于页面上的所有div

我有一些动态创建的div。 它们看起来像这样:

 
No Move
No Move
No Move
Move Me
No Move
No Move
No Move
Move Me

这是我想要做的,所以我可以有一个脚本将执行每个div。 这是我的脚本不起作用:我想移动.item-moveeee

 $(".item-logo").mouseover(function() { // Set the effect type var effect = "slide"; // Set the options for the effect type chosen var options = { direction: "left" }; // Set the duration (default: 400 milliseconds) var duration = 500; $(this).next().toggle(effect, options, duration); }).mouseout(function(){ $(this).next().hide('slide',{direction:'left'}); }); 

这是一个无效的小提琴: http : //jsfiddle.net/daveferrara1/4gBGq/

任何帮助,将不胜感激:

感谢@keypaul这里的小提琴jsfiddle.net/keypaul/U2w37

 
No Move
No Move
No Move
Move Me
No Move
No Move
No Move
Move Me
$(".item-logo").mouseover(function() { // Set the effect type var effect = "slide"; // Set the options for the effect type chosen var options = { direction: "left" }; // Set the duration (default: 400 milliseconds) var duration = 500; $(this).parent().find('.item-move3').toggle(effect, options, duration); }).mouseout(function(){ $(this).parent().find('.item-move3').hide('slide',{direction:'left'}); });

关键是你说你正在动态创建

。 要为动态创建的对象创建jQuery函数触发器,请尝试如下:

#1给你的div包装/父母:

 
No Move
No Move
No Move
Move Me

#2尝试以下jQuery函数:

 $(document).ready(function() { $(".parent").on("mouseover","div.item-logo",function () { // do what ever you want $(this).parent().find('.item-moveeee').html("*move*"); }); $(".parent").on("mouseout","div.item-logo",function () { // do what ever you want $(this).parent().find('.item-moveeee').html("Move Me"); }); }); 

工作小提琴: http : //jsfiddle.net/TyQ4V/