What is the correct way to get a control that was rendered by ASP.NET with jQuery?
Example: I have a checkbox that was generated like this:
<input id='ctl00_Content_chkOk' type='checkbox' name='ctl00$Content$chkOk' />
If I want to select it to get if it’s checked, I tried this:
$('form input[name=chkOk]').attr('checked')
and
$('chkOk').attr('checked')
But it didn’t work, I had to do it like this
$('form input[name=ctl00$Content$chkOk]').attr('checked')
And I guess this would’ve worked too:
$('ctl00$Content$chkOk').attr('checked')
Is this the correct way to do it? Is there another selector I can use?
You can use the server side control ClientID property:
or you could use the ‘ends with’ selector: attribute$=value