use*_*875 4 javascript jquery children parent-child css-selectors
我有一些像这样的div.
<div class"parent">
<div class"child">
Some Stuff Here
</div>
</div>
<div class"parent">
<div class"child">
Some other kinda Stuff Here
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想单击父类并仅在该父级内显示子类,而不显示其他父类中的其他子类.
$(document).on('click', '.parent', function(){
$(this).find($('.child').show(500));
});
Run Code Online (Sandbox Code Playgroud)
将选择器字符串传递给find()非对象 - 您传递的是jQuery对象.你也class"parent"应该有无效的HTML class="parent".
$(document).on('click', '.parent', function(){
$(this).find('.child').show(500);
});
Run Code Online (Sandbox Code Playgroud)