So for reasons beyond my control, I'm using jquery 1.4.2 and chrome..
I'm having a ludicrous amount of trouble trying to get detecting a check box is checked....working...
Here is what I have...
HTMl generated by asp.net Mvc3
<input type="checkbox" name="criteriaVm.WasApproved" id="criteriaVm.WasApproved">
Various versions I've tried
var ob = $("#criteriaVm.WasApproved");// is valid
var chk = ob.attr('checked'); // undefined
chk = ob.prop('checked');//crash
chk = ob.get(0).checked;//crash
chk = ob.get(0).is(":checked");//crash
chk = ob.is(":checked");//undefined
chk = ob.is(":checked");// always returns false
I've tried others before I started keeping track to make sure I wasn't just going in circles...
Does anyone know what version works on the old school jquery i'm, stuck with?
var ob = $("#criteriaVm.WasApproved")is does not select the element withid="criteriaVm.WasApproved"(andob.length;returns0).It selects an element with
id="criteriaVm"that has a class nameclass="WasApproved"(which does not exist)Having a
.,[or]in anidattribute will always cause problems with jquery selectors, which is why theHtmlHelpermethods replace those characters with an_(underscore) when generating theidattribute.Change your
idattribute toid="criteriaVm_WasApproved"(or anything you like that does not contain invalid characters) and use