what does this $('#id', javascript_object);
mean in jquery . I know that we can pass a context in the second parameter to the selector . But what happens when the second parameter is a javascript object 开发者_StackOverflow中文版.
Thanks in advance for the help .
The second parameter is the selector context. It restricts searching to a specific document object or the children of a certain DOM element.
By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function. For example, if within a callback function we wish to do a search for an element, we can restrict that search:
$('div.foo').click(function() { $('span', this).addClass('bar'); });
Since we've restricted the span selector to the context of this, only spans within the clicked element will get the additional class.
In the example you show, you would be searching for the element with the ID id
among the children of javascript_object
.
精彩评论