Wes
Wes

Reputation: 301

JQuery .is :checked returns false every time

Ok, I've been fiddling with this for almost 40 minutes now... WTF am I doing wrong?

http://jsfiddle.net/aMhjJ/

 <input type="Checkbox" name="E1019" id="E1019" value="1">
 <div id="result"></div>

Javascript:

$('#E1019').change(function () {

    if ($('E1019').is(':checked')) {
            $('#result').html('checked');
        } else {
            $('#result').html('unchecked');
        }
});

Problem solved: Missing # in if statement: $('E1019') should be $('#E1019')

Upvotes: 1

Views: 4864

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388436

You have used element selector instead of id selector - missing # in front of E109

if ($('#E1019').is(':checked')) {

Demo: Fiddle


But you can also use the checked property of the dom element

$('#E1019').change(function () {
    if (this.checked) {
        $('#result').html('checked');
    } else {
        $('#result').html('unchecked');
    }
});

Demo: Fiddle

Upvotes: 6

Related Questions