JQuery: find child elements from an existing selec

2020-02-01 08:09发布

问题:

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?

回答1:

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();


回答2:

You can use multiple comma-separated selectors:

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



回答3:

I think you are looking for:

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

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



回答4:

$(this).children('#inpouter[type=test]:first').focus();

Should do the trick...