javascript - Determining whenever user checks or unchecks a checkbox -
here code:
$(document).ready(function () { $("input[type='checkbox'][name='mycheckboxname']").change(function () { if ($(this).checked == true) { //do (script 1) } else { //do else (script 2) } }) });
what want accomplish have 2 scripts running depening whenever user checks or unchecks "mycheckboxname" checkbox. problem above code script 2 run looks if $(this).checked
false
if user checks checkbox
. using $(this)
wrong way?
checked
dom property of element, $(this)
returns jquery object.
you use dom property:
if (this.checked)
there's no reason wrap this
in jquery instance that. mean, can:
if ($(this).prop("checked"))
...but doesn't useful on top of this.checked
.
side note:
if (someboolean == true)
is roundabout way of writing
if (someboolean)
i mean, why stop there? why not
if ((someboolean == true) == true)
or
if (((someboolean == true) == true) == true)
or... ;-)
Comments
Post a Comment