3

I am trying to bind a click event to a div to toggle a checkbox thats inside of it. I tryed this:

$(".extraOp").bind('click', function(){
        var chk = $(this).find('input');
        chk.attr('checked', !chk.attr('checked'))
    });

The problem is that it only works one time, check and uncheck and then nothing. Any ideas ?

Thanks!

1 Answer 1

5

use .prop() instead of .attr()

chk.prop('checked', !chk.prop('checked'))

or

chk.prop('checked', function(i, checked){
    return !checked
})

Read Prop vs Attr

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.