【发布时间】:2013-07-05 00:38:57
【问题描述】:
单击.button 时,我正在尝试使用jquery 将.thumb 附加到另一个最后一个div 中
这是jquery函数:
$('.thumb').hover(function() {
$(this).find('.close').fadeIn();
}, function() {
$(this).find('.close').fadeOut();
});
$('.close').click(function() {
$(this).parent().fadeOut('slow');
});
$('.button').click(function() {
$html = '<div class="thumb">';
$html += '<img src="http://findicons.com/files/icons/1979/social/50/wordpress.png" />';
$html += '<div class="close">X</div>';
$html += '</div>';
$('.box').append($html);
});
我遇到此代码的障碍是附加的 div 不服从悬停事件或在 .close 上使用点击功能
非常感谢您的帮助,谢谢!
【问题讨论】:
-
我认为浏览器在开始时为每个元素设置了事件,如果您在加载页面后附加元素,它将无法正常工作。最好在创建新元素后设置悬停事件或为创建元素的上一级设置悬停
-
我使用了单独的组件,包含悬停事件,点击功能和
$.ajax,感谢回复!
标签: jquery jquery-hover