views:

176

answers:

2

Ok this is a general question about how to solve this issue, not to find some work around for the example given.

Lets say I have a $(this) object and it is a select, if I want to select the selected option and I had an id I could just bust a

$('#id option:selected')

game over.

but with a this I can't go $(this+' option:selected') or anything like that.

I am not so concerned with selecting the option:selected in the example so I don't want to know a workaround solution for this instance.

What I want to know is in general how you combine the subselectors like :has or option:selected with a $(this) situation.

Thanks.

+8  A: 

By using the optional context parameter:

$('option:selected', this)
Crescent Fresh
Ah yes. I tend to forget about the second context parameter :)
Jonathan Sampson
jQuery( expression, [context] )
Jonathan Sampson
Thank you, this was exactly what I wanted to know.
@Shog9: Holy. You can *edit* my answer? You're making me look good. Thanks.
Crescent Fresh
Rack up the reputation points and you gain extra powers on SO.
Diodeus
+2  A: 

you could also do:

$(this).find('option:selected');
mkoga