Sunday, 15 June 2014

javascript - Select children where not within container jquery -



javascript - Select children where not within container jquery -

this seem easy problem having problem figuring 1 out. illustration given sscce , have larger problem attempts solve. in order work query must not contain immediate kid selectors (>) due dom tree beingness bit more complex example.

my goal here select children whom aren't underneath parent contains class. in illustration trying select 2 div containers hello , world not foo , bar.

here plunker has code in convience. http://plnkr.co/edit/4zskafts5x7x2kladj2v?p=preview

using html:

<div id="root" class="parent"> <div> <div class="child">hello</div> <div class="child">world</div> </div> <div class="parent"> <div> <div class="child">foo</div> <div class="child">bar</div> </div> </div> </div>

and javascript:

var root = $('#root'); $(':not(.parent) .child', root).css('font-weight', 'bold');

i seeing result:

hello

world

foo

bar

but is

hello

world

foo

bar

to reiterate want elements class child dont have parent class parent starting given node (in illustration #root).

var root = $('#root'); $('.child', root).not($("#root .parent .child")).css('font-weight', 'bold');

jsfiddle example

javascript jquery jquery-selectors

No comments:

Post a Comment