admin管理员组文章数量:1134084
I have the following HTML:
<div id="mydiv">
<div class="myclass"></div>
</div>
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?
I have the following HTML:
<div id="mydiv">
<div class="myclass"></div>
</div>
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?
5 Answers
Reset to default 335Try:
$('#mydiv').find('.myclass');
JS Fiddle demo.
Or:
$('.myclass','#mydiv');
JS Fiddle demo.
Or:
$('#mydiv .myclass');
JS Fiddle demo.
References:
find()
.- Selector context.
Good to learn from the find()
documentation:
The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.
Try this
$("#mydiv div.myclass")
You'll do it the same way you would apply a css selector. For instanse you can do
$("#mydiv > .myclass")
or
$("#mydiv .myclass")
The last one will match every myclass inside myDiv, including myclass inside myclass.
If you want to select every element that has class attribute "myclass" use
$('#mydiv .myclass');
If you want to select only div elements that has class attribute "myclass" use
$("div#mydiv div.myclass");
find more about jquery selectors refer these articles
try this instead $(".video-divs.focused")
. This works if you are looking for video-divs that are focused.
本文标签: javascriptHow can I select item with class within a DIVStack Overflow
版权声明:本文标题:javascript - How can I select item with class within a DIV? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736781748a1952637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论