简体   繁体   中英

How to access specific div child of certain class?

In my div i have a child div of class "someClass". I want to access that child by classname, not id.

EDIT: Only in this particular div, not all the other divs with same classname

var childOfNamedDiv = $('#namedDiv>.someClass')
var div = $('.someClass');

参见jQuery选择器

只需使用类选择器:

$('div>.someClass').toggle()

if you already have a reference to the jquery object that is the parent of the div that you want to find:

var parent = $("#someDiv"); // this is the div that you may alread have found earlier
var child = parent.children(".someClass");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM