开发者

getting valueof label in next column

i am trying to get the value in the next column ie Link1 labelwhen clicking on link1? how to do this with 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>
           开发者_JAVA技巧     <td>
                    <a id="link2">Link2</a>
                </td>
                <td>
                    <label>
                        Link2 label</label>
                </td>
            </tr>
        </table>


Use this:

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

Hope this helps.


This will work:

$("#Link1").click ( function () {

    alert ( $(this).parent ().siblings ('td').first ().children ('label').text () );
} );

See a demo for all links, at jsFiddle.


Try -

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

A jsfiddle example.


try

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


add return false also.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜