views:

61

answers:

4

Hello!

I have one very interesting question (for me :) )..

I'm using jquery and I want to find in HTML the first tag after my reference one .

For example my HTML :

    <a href="#" class="A" >A</a>
    <table>
        .....
    </table>
<a href="#" class="B" >A</a>
    <table>
        .....
    </table>
<a href="#" class="c" >A</a>
    <table>
        .....
    </table>

I want to select the first table after <a href="#" class="A" >A</a>, the first table after <a href="#" class="B" >B</a> ... with jquery . Because just this link is reference tag for me in HTML , all tables are the same (don't have any class, ID ...) , and I don't know how many table can be :( ..

Thanks !!!

+4  A: 

Use next:

$('a').click( function() {
    var tbl = $(this).next('table'); // find the next table element following the clicked link
});
tvanfosson
+2  A: 
$('a.A').next('table') // Get the next <table> element after the a.a

or

$('a.A').next() // Get the next element after the a.a
TiuTalk
+2  A: 

With jQuery, you can use + to get an element directly after another element. For example, to get the table directly after the A link, you could use this:

$(".A + table")

You can also use the next method.

icktoofay
+2  A: 

To get the table tag, use the .next() selector:

For exmaple the class="A" link, to get the table:

$(".A").next("table");
Nick Craver