开发者

JQuery: find child elements from an existing selector

开发者 https://www.devze.com 2023-01-01 07:45 出处:网络
Im sure the solution is simple bu开发者_高级运维t I cant figure it out :( I need to combine two jquery selectors in one selector:

Im sure the solution is simple bu开发者_高级运维t 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?


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


You can use multiple comma-separated selectors:

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


I think you are looking for:

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

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


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

Should do the trick...

0

精彩评论

暂无评论...
验证码 换一张
取 消