开发者

jquery , selector, find, text

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开发者_如何学C 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 !!!


Use next:

$('a').click( function() {
    var tbl = $(this).next('table'); // find the next table element following the clicked link
});


$('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


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.


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

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

$(".A").next("table");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜