应用早期选择器后应用选择器
我在页面上有.product1的多个项目。 当用户将鼠标hover在缩放按钮上时,我想获取类image
的HTML。 我尝试过:
$(this).closest(".product1")(".image").html()
但这没有任何回报。
这是我的代码:
$(document).ready(function () { $(".productzoom").hover(function () {//also add this function to click console.log($(this).closest(".product1")(".image").html()); }); });
你刚刚省略了.find()
。
使用:
$(document).ready(function () { $(".productzoom").hover(function () {//also add this function to click console.log( $(this).closest(".product1").find(".image").html() ); }); });
jsFiddle示例