在过去的几个小时里,我试图将隐藏div的显示设置为可见,但我无法通过jquery访问该div。
单击按钮后,我将值传递给函数。 从那里我想设置一个隐藏的div可见,这是在父的一个div内。但我无法达到那个div。
我尝试过parent(),nearest(),find()和其他一些事情,但未能达到那个div。
以下是我到目前为止所做的代码jsfedle
谢谢。
答案 0 :(得分:2)
你的onclick事件没有元素上下文,因为你没有将它作为参数传递。由于您在创建的点击功能中不存在this
。
您可以使用jquery附加事件:
$('.product-select').click(function(){
$(this).parent().find( ".product-selected" ).show();
});
答案 1 :(得分:0)
parent()
会将您转到父级,然后在其中查找.product-selected
使用.find()
$('.product-select').click(function(){
$(this).parent().find(".product-selected").show();
});
答案 2 :(得分:0)
.closest()上传DOM,我想你需要.find()......