简体   繁体   中英

How to check if input check or not with jquery

I have this switcher (Checked):

<div class="switch try">
<label><input checked="" type="checkbox" class="checkit"><span class="lever switch-col-green"></span></label>
</div>

How to know if this one is checked or unchecked when a user click on it ?

Here what i tried:

$(document).on('click','.try',function(e){
                        if($(".checkit").is(':checked')) {
                            alert("checked");
                        } else {
                            alert("Not checked");
                        }
});

But i don't get it working !

Try to use this:

$(".checkit:checked").length > 0;

or

$(".checkit").is(":checked")

You need to change your html from checked="" -> checked

<input checked type="checkbox" class="checkit">

Jquery is correct as is

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM