Get text value of span in repeater by using javascript or jquery


i can't get value of span (or label) here is my html code

<asp:Repeater ID="rpt_district" runat="server" >
            <tbody id='bodies'>

                    <span id="district_id"><%# Eval("DISTRICT_ID") %></span>
                <td><%# Eval("DISTRICT_NAME") %></td>
                    <asp:Label ID="lb_city_id" runat="server" Text='<%# Eval("CITY_ID") %>'></asp:Label>
                <td style="float:left; margin-left:5px;">
                    <asp:CheckBox ID="cb_status" runat="server" onclick="javascript: return false;" />
                    <asp:HiddenField ID="hf_status" Value='<%# Eval("ENABLE") %>' runat="server" />
                    <div style="float:left; margin-left:4px;" >
                        <asp:ImageButton ID="ib_edit" runat="server" ImageUrl="~/Hinh/icons/Edit.png" ToolTip="Edit" />
                    <div style="float:left; margin-left:4px;">
                        <asp:ImageButton ID="ib_delete" runat="server" ImageUrl="~/Hinh/icons/Trash.png" 
                                        ToolTip="Delete" CommandArgument='<%# Eval("DISTRICT_ID") %>'
                                        OnClientClick="getvalue(); return false;"/>



i want to get value of district_id in span tag (or label is ok) by using javascript when clicking on imagebutton

function getvalue() {
    var thisspan = $('.district_id').eq(0);

but it just get the value in first column be cause of ea(0) i'm just want to get value by using javascript or jquery not code behind thanks.....


You are searching after a class but you have an id

var thisspan = $('#district_id').eq(0);

. is the selector for classes and # is selector for ids. Your html has the id not the class, so your code should be like:

var thisspan = $('#district_id').eq(0);

Also, id's are unique in html so you do not need the .eq(0):

var thisspan = $('#district_id');

Finally, to get the text value inside of the span tah you need to do:

var thisspan = $('#district_id').html();


var thisspan = $('#district_id').text();

Add a css class to your image button like this. No two elements in the DOM should have the same ID.

By : Krishna

This video can help you solving your question :)
By: admin