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?
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.
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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With