I have a <asp:Checkbox /> and I want to see whether it’s checked or not via jQuery. Problem is, it always returns false. Does it have to do with the fact that I’m selecting the element via class?
The js
$(document).ready(initialize);
var map;
function initialize() {
var x;
x = $(".chkSetMap");
x.click(setMap);
}
function setMap() {
if ($('.chkSetMap').attr('checked') == true) {
$(".comboMap").attr("disabled", true);
}
}
the checkbox
<asp:CheckBox ID="chkSetMap" CssClass="chkSetMap" runat="server" />
the checkbox rendered
<span class="chkSetMap"><input id="ctl00_ContentPlaceHolder1_chkSetMap" type="checkbox" name="ctl00$ContentPlaceHolder1$chkSetMap" /></span>
Try using the
.is()method and the:checkedshorthand selectorworking example: http://jsfiddle.net/hunter/5XA7D/ UPDATED!
Since ASP.Net server controls are awesome it’s wrapping your checkbox in a
span. Thespanhas thechkSetMapclass, not the checkbox.