jquery selector multiple classes on set of <div>'s (contains one class, not the other)
Question by Dave Jay
This may be easier than what I’ve tried. I have a set of <div>
‘s such as <div id="site-abc" .. "site-def">
and each has similar HTML content. The DIV’s have multiple classes like "ui-tabs-panel class2 ui-tabs-hide"
. One does not have ui-tabs-hide. That’s what I need a selector for, and then from that I need to find unique text within that DIV that’s within bingo!.
What’s the right jQuery selector code for the following steps: A) find right <div>
with class="ui-tabs-panel"
but NOT CONTAINING "ui-tabs-hide"
; B) take that selector result and find ('th.target2')
and get the .text()
?
var tabs = $('#editors.not(.ui-tabs-hide');
var my_text = tabs.find('th.target2').text();
<div class="grid-editor">
<div id="editors" class="ui-tabs">
<div id="site-abc" class="ui-tabs-panel class2 ui-tabs-hide">
//duplicates HTML like "site-ghi" including <th>bingo!</th>
</div>
<div id="site-def" class="ui-tabs-panel class2 ui-tabs-hide">
//duplicates HTML like "site-ghi" including <th>bingo!</th>
</div>
<div id="site-ghi" class="ui-tabs-panel class2”>
<table class=”my-table”>
<thead>
<tr>
<th class="target1">abc1</th>
<th class="target2">bingo</th>
</tr>
</thead>
</div>
</div>
</div>
Answer by Starx
You almost got it. Use :not
selector to omit the one you don’t need.
var divs = $('.ui-tabs-panel:not(.ui-tabs-hide)');
I am not sure if this is related to the problem, but there is mistake in your selector statement as well.
var tabs = $('#editors.not(.ui-tabs-hide');
//^ No Closing bracket