tags:

views:

56

answers:

5

hi,

how can I use the option :checked with $(this) in jQuery ?

i.e. $(this:checked) ?

thanks

+1  A: 

Like this:

if ($(this).is(':checked'))
SLaks
+6  A: 
$(this).filter(":checked");

or if you're testing it

if ($(this).is(":checked")){
    // ...
}
MiffTheFox
Unless you're doing something _really_ weird, `this` will only be one element.
SLaks
@Slaks - Yes, but that seems to be what the original intent of the question was. Plus, you can do something like `$(this).filter(":checked").addClass("checked")` to only add the class if the element is checked.
MiffTheFox
A: 

try it $(':checked', $(this))

vitaly.batonov
That looks for checked input *inside* `this`.
bobince
+1  A: 

Use is() method.

$(this).is(':checked') returns boolean.

Boris Guéry
+1  A: 

The checkbox Node has its own property checked, so:

if (this.checked) ...

there is no need to make jQuery do a bunch of work by packaging that trivially simple check in a selector. The DOM version is perfectly readable.

bobince