jquery select div 在调用元素的父元素中
jquery select div inside parent of calling element
在过去的几个小时里,我试图将隐藏的 div 的显示设置为可见,但我无法使用 jquery 显示 div。
单击按钮后,我将值传递给函数。
从那里我想设置一个隐藏的 div 可见,它位于父级的 div 之一内。但我无法达到 div.
我已经尝试了 parent()、closest()、find() 和其他几种方法,但未能达到 div。
这是我到目前为止所做的代码jsfedle
谢谢。
您的 onclick 事件没有元素上下文,因为您没有将它作为参数传递。由于 this
在您创建的点击函数中不存在。
您可以使用 jquery 附加事件:
$('.product-select').click(function(){
$(this).parent().find( ".product-selected" ).show();
});
parent()
将带您到父级,然后在其中找到 .product-selected
使用 .find()
$('.product-select').click(function(){
$(this).parent().find(".product-selected").show();
});
.closest() 上升到 DOM,我猜你需要 .find()...
在过去的几个小时里,我试图将隐藏的 div 的显示设置为可见,但我无法使用 jquery 显示 div。
单击按钮后,我将值传递给函数。 从那里我想设置一个隐藏的 div 可见,它位于父级的 div 之一内。但我无法达到 div.
我已经尝试了 parent()、closest()、find() 和其他几种方法,但未能达到 div。
这是我到目前为止所做的代码jsfedle
谢谢。
您的 onclick 事件没有元素上下文,因为您没有将它作为参数传递。由于 this
在您创建的点击函数中不存在。
您可以使用 jquery 附加事件:
$('.product-select').click(function(){
$(this).parent().find( ".product-selected" ).show();
});
parent()
将带您到父级,然后在其中找到 .product-selected
使用 .find()
$('.product-select').click(function(){
$(this).parent().find(".product-selected").show();
});
.closest() 上升到 DOM,我猜你需要 .find()...