Getting the label value in the next column

I am trying to get the value in the next column, i.e. Link1, when you click on link1? how to do it using jquery? I tried:

$("#Link1").clicked( function() { alert($("td(2) label.attr('text')")); }); <table> <tr> <td> <a id="link1">Link1</a> </td> <td> <label> Link1 label</label> </td> </tr> <tr> <td> <a id="link2">Link2</a> </td> <td> <label> Link2 label</label> </td> </tr> </table> 
+4
source share
5 answers

Use this:

 $("a").click(function(){ var $label = $(this).closest("tr").find("label"); alert( $label.text() ); }) 

Hope this helps.

+1
source

This will work:

 $("#Link1").click ( function () { alert ( $(this).parent ().siblings ('td').first ().children ('label').text () ); } ); 

See the demo for all links in jsFiddle .

+1
source

Try it -

 $("#link1").click( function() { alert( $("#link1").parent().next().find("label").text() ); }); 

A jsfiddle example.

+1
source

to try

 $("#Link1").clicked( function() { alert($(this).parent().siblings('td > label').html()) }); 
0
source

add return false as well.

 $("#Link1").click(function(){ var $lblValue = $(this).parent().siblings().find("label"); alert( $lblValue .html()); return false // this will stop the jumping }) 
0
source

All Articles