I'm trying to find out how to check if a checkbox is checked or not.
I know about the :checked
selector but I'm trying to do this using the $(this)
object.
$(".permission_checkbox").live('change',function(){
if($(this+":checked").length==0){
a开发者_运维问答lert('remove');
} else {
alert('add');
}
});
This code always calls alert('add')
!
Thanks for any help & merry christmas
While you asked about using selectors, you really don't need jQuery for this.
Checkboxes have a checked
property you can access directly, which will be much faster than adding the overhead of jQuery object creation + method call + selector engine.
if( this.checked ) {
// it was checked
}
Try jQuery.is
:
$(this).is(":checked")
Hope it helps
Try this to select the checked input.
$(this).is(':checked')
hope it will help..
What about
$(this).find(':checked')
Instead of +
you should use shortcut for find $(":checked", this)
精彩评论