JQuery:从现有选择器中查找子元素

Bru*_*uno 6 jquery css-selectors

我确定解决方案很简单,但我无法弄明白:(我需要在一个选择器中组合两个jquery选择器:

$(this) + $('input[type=text]:first')
Run Code Online (Sandbox Code Playgroud)

$(this)是例如div#selected所以结果应该是:

$('div#selected input[type=text]:first').focus();
Run Code Online (Sandbox Code Playgroud)

怎么做?

Fel*_*ing 8

只需使用.find():

获取当前匹配元素集中每个元素的后代,由选择器过滤.

$(this).find('input[type=text]:first').focus();
Run Code Online (Sandbox Code Playgroud)

或者将上下文设置为this:

$('input[type=text]:first', this).focus();
Run Code Online (Sandbox Code Playgroud)