Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: find child elements from an existing selector

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?

like image 850
Bruno Avatar asked May 24 '10 12:05

Bruno


People also ask

How would you find a child element with a specific class using jQuery?

children(selector) – In jquery you can achieve this task by using the method named . children(). It takes the selector as a parameter and changes the children element with the specified name.

How do you get the children of the $( this selector?

Answer: Use the jQuery find() Method You can use the find() method to get the children of the $(this) selector using jQuery. The jQuery code in the following example will simply select the child <img> element and apply some CSS style on it on click of the parent <div> element.

How do you get children of children in jQuery?

The children() method returns all direct children of the selected element. The DOM tree: This method only traverse a single level down the DOM tree. To traverse down multiple levels (to return grandchildren or other descendants), use the find() method.

How do I get all Div children?

If You want to get list only children elements with id or class, avoiding elements without id/class, You can use document. getElementById('container'). querySelectorAll('[id],[class]'); ... querySelectorAll('[id],[class]') will "grab" only elements with id and/or class.


2 Answers

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();
like image 61
Felix Kling Avatar answered Dec 19 '22 03:12

Felix Kling


You can use multiple comma-separated selectors:

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

like image 27
Markos Fragkakis Avatar answered Dec 19 '22 04:12

Markos Fragkakis