Zaki Zaki - 11 months ago 80
jQuery Question

how to get label text inside repeater

I am trying to get the text of a lable when someone clicks on a link button:

this is my code :

$(document).ready(function () {

$('[id*="lnkbtn_Remove"]').click(function (event) {

var id = $("span[id*=lbl_Reference]").text();

But this gets me all the reference in the reapter as I am using "*". Is there anyway to get the actual reference on the row it has been clicked. Here is my html:

<asp:Repeater ID="rpt" runat="server" >
<div class="test">
<div style="width: 230px;">
<asp:Label ID="lbl_Len" runat="server" CssClass="font_bold"></asp:Label>
<br />
<asp:Label ID="lbl_Reference" runat="server"></asp:Label>
<td align="left">
<div style="width: 80px;">
<asp:LinkButton ID="lnkbtn_Remove" runat="server" CssClass="rpt_item_Remove">Remove</asp:LinkButton>


Answer Source

You can get it by something like this,

 var lablelId = $(this).closest('.test').find('[id*=lbl_Reference']).attr('id');
 var lablelText = $(this).closest('.test').find('[id*=lbl_Reference]').text();