Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery event.target and is(":checked") not working

Tags:

jquery

Just a simple question.

I'm using

console.log(jQuery(event.target).is(":checked"));

and it returns false everytime.

If I do a console.log(jQuery(event.target)) is prints out the input box, so I know event.target is correct.

I can't use this here because the jQuery event is bound to a parent div.

Any ideas why this wouldn't work? Seems easy enough.

EDIT######################################### Rest of code:

jQuery(".core-create-install-pkg-parent").live("click", function(event){
var cls = jQuery(event.target).attr("type");
if(cls != "checkbox"){
    event.stopPropagation();
    jQuery(".core-create-install-pkg-child:first", this).toggle();
}else{
    console.log(event.target);
    if(jQuery(event.target).is(":checked")){
        console.log("it's checked");
        jQuery("input[type=checkbox]", this).removeAttr('checked'); 
    }else{
        console.log("not checked");
        jQuery("input[type=checkbox]", this).attr("checked", true);
    }
}
});

And the html looks like:

<div class="core-create-install-pkg-parent">
  <div class="core-create-install-pkg-title">
    <input type="checkbox" value="" checked>
    plugins
  </div>
</div>
like image 992
Senica Gonzalez Avatar asked Nov 27 '22 14:11

Senica Gonzalez


1 Answers

No need for jQuery:

event.target.checked

should work if event.target is a checkbox. But then, your code should work as well... if it does not, either the element is not a checkbox or something else is wrong.

like image 164
Felix Kling Avatar answered Dec 09 '22 21:12

Felix Kling