1

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”&gt;
            <table class=”my-table”&gt;
                <thead>
                    <tr>

                        <th class="target1">abc1</th>
                        <th class="target2">bingo</th>
                    </tr>
                </thead>
        </div>
    </div>
</div>
4

5 回答 5

1

尝试这个 :

var val = $('div.ui-tabs-panel:not(.ui-tabs-hide)').find('th').filter(".target2").text();
alert(val);

见这里:http: //jsfiddle.net/YxUfq/6/

于 2012-05-12T05:15:27.583 回答
1

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 
于 2012-05-12T04:26:58.730 回答
0

我认为最酷的方法是:

var text = $(".ui-tabs-panel:not(.ui-tabs-hide) th.target2").text();

希望能帮助到你

于 2012-05-12T04:57:02.570 回答
0
var my_text = $('#target2', '.ui-tabs-panel:not(.ui-tabs-hide)').text();

小提琴

于 2012-05-12T04:30:26.047 回答
0
var divs = $('.ui-tabs-panel:not(.ui-tabs-hide)');

或者

var divs = $('.ui-tabs-panel').not('.ui-tabs-hide');

然后发现target2你可以试试这个:

$('th#target2', divs).text();

根据您的标记,'target2'id不是class. 所以正确的意志th#target2,不是th.target2

于 2012-05-12T04:47:56.287 回答