Imran Jawaid
Imran Jawaid

Reputation: 471

how to access table inside a table using jquery

i got a table inside a table like

<table class="xyz">
<tr>
<td>
<table>
<tr>
<td>
<label>hello<label>
<input></input>
</td>
</tr>
</table>
</td>

</tr>
</table>

i want to get the inside table elements using jquery

Upvotes: 0

Views: 838

Answers (4)

Jewel
Jewel

Reputation: 93

<table class="xyz" id="xyz">

$(document).ready(function() {

    $('#xyz tbody tr').live('click', function (event) {
        $(this).find("input").each( function( index, item ) {
              alert(index+"----"+$(this).val() );
        });
    }); 
});

Upvotes: 0

gdoron
gdoron

Reputation: 150263

This would do it:

$('table.xyz table')... // It will select the <table> which is inside of <table>
                        // with the class xyz

If you meant by inside table elements to all of the elements:

$('table.xyz table *')... // It will select all the elements that inside the 
                          // <table>with the class xyz which is inside of <table>

If you want only the inputs:

$('table.xyz table input')...

descendant selector docs:

Description: Selects all elements that are descendants of a given ancestor.

Change the width of <td> in that table:

$('table.xyz table td').css('width' ,'300px');

Upvotes: 2

Fernando Diaz Garrido
Fernando Diaz Garrido

Reputation: 3995

In your example it would be

$('table.xyz table')

The first part 'table.xyz' will select the upper table (table with a class xyz) and then the second part will select any child with a table tag

Upvotes: 1

Andrei Bularca
Andrei Bularca

Reputation: 1024

You can use find method from jQuery.

Upvotes: 0

Related Questions