You can't have hidden input be a checkbox, so it won't have a checked
property. You can use a type="checkbox"
and hide it with display:none
if you need it to be a checkbox, or you can simply use the hidden input with a 0
or a 1
instead to kind of simulate it.
jQuery and IE: Checking for hidden inputs "checked"-attribute does not work
-
28-06-2022 - |
Frage
I've been trying to check if my input[type=hidden] has an checked="checked" attribute. That input field looks like this:
<input type="hidden" checked="checked" name="1_WILLINFOS">
In Firefox it works just fine by using:
jQuery(selector).find('input[name=1_WILLINFOS]').attr('checked') == "checked"
But IE10 always gives me a false.
By now I tried to use the following:
.attr("checked") == "checked"
.attr("checked") == true
.is(':checked')
With all of them giving me a false.
Any ideas? Thanks
Lösung
Andere Tipps
You can have hidden element with any attribute . E.g
<input type="hidden" abc="xyz" name="1_WILLINFOS">//is an `input` type `hidden` with attribute abc having value xyz
In Your case,
<input type="hidden" checked="checked" name="1_WILLINFOS">//is an `input` type `hidden` with `attribute` checked with value `checked`
$('input[name=1_WILLINFOS]').attr('checked') == "checked" //is an element with name '1_WILLINFOS' and attribute checked set to 'checked' .So it will surely match and return true
but,
.attr("checked") == true //will fail as you set `checked` attribute value to 'checked' and your are checked for true condition.so you must check for `.attr("checked") == 'checked`
$('input[name=1_WILLINFOS]').is(':checked'));// will check for attribute checked if its set it will return you true.
Here is working fiddle for you
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow