开发者

How to use specific selectors on $(this)

开发者 https://www.devze.com 2023-01-31 22:06 出处:网络
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.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消