J.Olufsen
J.Olufsen

Reputation: 13915

How to select a div with specific id inside table tr?

I need to show hidden tr which was div with id="thumbnail3". How to do it using jQuery?

HTML:

<html>
    <body>
        <table class="table" id="table_of_books">
            <tbody>
                <tr>
                <td></td>
                </tr>
                <tr>
                    <td>
                        <div class="thumbnail">
                            <div id="thumbnail3" class="">  ...</div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="thumbnail">
                            <div id="thumbnail4" class="">  ...</div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

Update:

I am trying to handle pagination. I am getting data using async json request. I am trying to hide all received entries in table. When Previous/Next button pressed I am trying to show one more entry. The only static is table and tbody (tr and td generated asynchronously by js). I am thinking of hiding tbody at the beginning. And then show tbody and only one element which is relevant to current page. Is there more elegant way to do it?

Upvotes: 0

Views: 2680

Answers (4)

Adil Shaikh
Adil Shaikh

Reputation: 44740

$('#thumbnail3').closest('tr').show();

as you asked I need to show hidden tr.

Upvotes: 4

97ldave
97ldave

Reputation: 5249

To select the div, use:

$("#thumbnail3")

jQuery id-selector

If you are trying to show the closest <tr> to your <div>, use the .closest() method:

$("#thumbnail3").closest('tr').show();

Upvotes: 1

painotpi
painotpi

Reputation: 6996

Assuming the id is static, you could do the following,

$("#thumbnail3").parents("tr").show()

The .parents() get the ancestors of each element in the current set of matched elements, optionally filtered by a selector. Read more about .parents()

Upvotes: 2

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382464

The standard solution is to use

$('#thumbnail3')

If you want to select it only if this element is in the table, you might do

$('table #thumbnail3')

but don't forget that you can't give a specific id to more than one element in HTML. If you're not specifically checking the element is in the table, you shouldn't use the latter, which is slower.

To show the tr, use

$('#thumbnail3').closest('tr').show();

Upvotes: 2

Related Questions