Check :enabled state of $(this) element in jQuery
Asked Answered
M

3

6

Maybe I'm missing something and failing at google all at that same time but how would I say similar to:

...
if ($(this:enabled)){
    //some code
}
...

I know normally you'd say something like $("#someID:enabled") but how to use with $(this)?

Moderate answered 31/12, 2014 at 20:25 Comment(2)
how do you concatenate a string to a variable?Hudgens
You mean $(this).is(':enabled'), rightHousecoat
B
13

You can use the is(selector) method like this:

if ($(this).is(':enabled')) {
    // some code
}
Balladry answered 31/12, 2014 at 20:27 Comment(4)
Always great stuff here at SO. This is what I needed, thanks.Moderate
Out of curiosity, is this $(":enabled", this) the same as $("option:selected", this)?Bobbitt
@TimLewis - if you mean that $(":enabled", this) is the same as $(this).find(":enabled"), yes it is ?Ez
@Ez Ah ok, .find not .is. Thanks for that clarification.Bobbitt
S
0

try this :

if($(this).is(':enabled'))
Sheelagh answered 31/12, 2014 at 20:27 Comment(0)
L
0

jQuery has a filtering method that you can use for this.

if( $(this).is(':enabled') ) { // do something here }

http://api.jquery.com/is/

Lyndseylyndsie answered 31/12, 2014 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.