views:

199

answers:

4

Hi there.

Im sure the solution is simple but I cant figure it out :( I need to combine two jquery selectors in one selector:

$(this) + $('input[type=text]:first')

$(this) is e.g div#selected so the result should be:

$('div#selected input[type=text]:first').focus();

How to do?

A: 

I think you are looking for:

$('input[type=text]:first', this).focus();

It will focus the input box in the context of div#selected

Sarfraz
Thank you. Knew it was easy :)
Bruno
A: 
$(this).children('#inpouter[type=test]:first').focus();

Should do the trick...

Brant
That's not exactly the same. It will only search the immediate children of the first selector. The example only cares if the element is a descendent of the first selector.
tvanfosson
True, I guess I made that assumption. The other answers are better here anyway (e.g. find)
Brant
+3  A: 

Just use .find():

Get the descendants of each element in the current set of matched elements, filtered by a selector.

$(this).find('input[type=text]:first').focus();

or set the context to this:

$('input[type=text]:first', this).focus();
Felix Kling
Thank you. Knew it was easy :)
Bruno
A: 

Use can use multiple comma-separated selectors:

http://api.jquery.com/multiple-selector/

Markos Fragkakis