Choosing an element's parent using jQuery selectors

I want to find a TD counter inside my TR where one of its TD matches my criteria. Here is the skeleton of my html structure,

<div class="pager">
        <table class="pager_table">
            <tbody>
                <tr>
                    <td></td>
                    <td id ="sometextPager_left"></td>
                    <td></td>
                ...................
        </table>
    </div>

And my jQuery selection code:

$('div.pager > table.pager-table td[id$="Pager_left"] :parent tr > td').length

It seems my selector is not working,

thank

+4
source share
3 answers

Try using a selector :has(),

$('div.pager > table.pager-table tr:has(td[id$="Pager_left"]) > td').length
+3
source

You do not have a class attribute in a div.

Change the following line:

<div class="pager">
0
source

:parent, jQuery . .

, TD , ID TD td[id] :has()

$('.pager > .pager_table tr:has(td[id]) > td').length // returns 3

JSFiddle: http://jsfiddle.net/TrueBlueAussie/ghLcyp54/1

0
source

All Articles