开发者

JQuery div child of td child of div

开发者 https://www.devze.com 2023-02-20 14:48 出处:网络
I want to select a set of DIV elements that are contained inside a set of TD elements. These TD elements are part of a table inside another DIV.

I want to select a set of DIV elements that are contained inside a set of TD elements. These TD elements are part of a table inside another DIV. The uppermost DIV has a given ID, and the TD elements have a specific class. If I select the lowermost DIV elements by targeting the TD elements at first, it works. However, there are more elements of this kind that are contained in another uppermost DIV elements different that the uppermost DIV I'm targeting.

Hope it makes sense.

I'm trying to do something like

$('div[id="uppermost"] > td.<classname> > div')

This works

$('td.<classname> > div')

but more items of what 开发者_StackOverflowI need are also selected.


Probably you want:

$('#uppermost td.whatever > div')

The ">" immediate child operator is probably what's making yours not work. The <td> elements are, as you say, inside a <table> (and inside <tr> elements too), so they're not immediate children of the container.


What about

$("div#uppermost > td.classname > div")

?

Would have been easier if we could get some markup


You need to get rid of the first ">" character in the query. The ">" is a selector for immediate children of the previous selector. Your selector is looking for TD elements that are directly children of the DIV.

Try this instead:

$('div#uppermost td.<classname> > div')
0

精彩评论

暂无评论...
验证码 换一张
取 消