JQuery to get text attribute of checkbox
I add a check box to the page using the following statement:
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e )
{
if (!IsPostBack)
{
CheckBox XChkBox = new CheckBox(); //instance of System.Web.UI.WebControls.CheckBox
XChkBox.ID = "someId"
XChkBox.Text = "someText"
somePlaceHolder.Controls.Add(XChkBox);
}
}
</script>
I need to get the Text attribute of this checkbox when I click. I tried $(this).attr('Text');inside $('input[type=checkbox]').click(function(){});, but it returns undefined.
Where am I mistaken? Please suggest.
amuses
ASP.NET displays the property of the Textserver control ASP:CheckBoxas an element labelimmediately after <input type="checkbox" />on the generated markup on the client looks something like this:
<input id="someId" type="checkbox" name="someId" />
<label for="someId"> someText </label>
You can get Text labelwith:
$("input:checkbox").click(function() {
var $label = $(this).next('label');
alert($label.text());
});