如何在DIV中选择具有类的项目? [英] How can I select item with class within a DIV?
本文介绍了如何在DIV中选择具有类的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下HTML:
<div id="mydiv">
<div class="myclass"></div>
</div>
我希望能够使用选择器来选择内部div
,但特定于mydiv
容器.如何使用jQuery实现此目标?
I want to be able to use a selector that selects the inside div
, but specific for the mydiv
container. How can I achieve this with jQuery?
推荐答案
尝试:
$('#mydiv').find('.myclass');
或者:
$('.myclass','#mydiv');
或者:
$('#mydiv .myclass');
参考文献:
很高兴从 find()
文档中学习:
Good to learn from the find()
documentation:
.find()和.children()方法类似,除了 后者仅沿DOM树向下移动一个级别.
The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.
这篇关于如何在DIV中选择具有类的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文