我有以下 HTML:
<div id="mydiv">
<div class="myclass"></div>
</div>
我希望能够使用选择器选择内部 div
,但特定于 mydiv
容器。我如何使用 jQuery 实现这一点?
最佳答案
尝试:
$('#mydiv').find('.myclass');
或者:
$('.myclass','#mydiv');
或者:
$('#mydiv .myclass');
引用资料:
很好学习find()
文档:
The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.
关于javascript - 如何在 DIV 中选择带有类的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6933763/