Reputation: 2491
I have been studying a piece of jQuery script and editing it for my needs for a few days now. It contains the following lines.
var newElement = $("#featured-post").clone();
var inputField = $("select", newElement);
I just don't understand what exactly the second line does as I haven't seen such a selector before (yes, I'm new to jQuery).
I can guess that it selects "" elements within the cloned element. But I have not read about this method of selection before. Could somebody explain a little bit about this selector? I've done some googling but didn't find anything related to this. Thanks a lot.
Upvotes: 1
Views: 76
Reputation: 8991
jQuery( selector [, context ] )
selector
- Type: Selector
- A string containing a selector expression
context
- Type: Element or jQuery
- A DOM Element, Document, or jQuery to use as context
Source: http://api.jquery.com/jQuery/#jQuery-selector-context
Upvotes: 1
Reputation: 73906
To make it simple for you, the below code:
$("select", newElement);
is same as doing:
$(newElement).find("select");
So, the selector will look for the select
element inside the newElement
cloned element.
Upvotes: 3