context, returns the original DOM node content passed to jQuery(), which is the second parameter of jQuery(). If not specified, context points to the current document
For example: $("p span",context);
means selecting the "p span" object from the context object. This is a usage of jQuery, which is to select Find objects within a certain range.
And $(dom)[0].attributes directly finds the attributes under the first dom. It is different from context and specifies the search object.
context Return value: Element
Newly added in jQuery1.3, it returns the original DOM node content passed to jQuery(), which is the second parameter of jQuery(). If not specified, the context points to the current document (document). It can be used with selector for Accurately detect selector query situations. These two properties are useful to plugin developers.
Example: Detect the content of the document used
jQuery code:
1 2 |
|
Result:
1 2 |
|
[Note]: $("ul", document. body).context.nodeName This sentence means to find the ul element in document.body.
Sample code one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
By default, the original DOM node passed to jQuery() is Document, and [object] will be returned in IE browser. Other browsers return [object HTMLDocument].
Sample code two:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
The return value of the above code is [object HTMLUListElement], but in IE browser it is [object]
The above is the detailed content of What is $(dom).context in JQuery code? how to use?. For more information, please follow other related articles on the PHP Chinese website!