Text
")"."/> Text")".">Home > Article > Web Front-end > What is the role of the $ symbol in jquery?
Related recommendations: "jQuery Tutorial"
$ is an alias for jQuery "class", $() constructs a jQuery object . Therefore, "$()" can be called jQuery's constructor.
jQuery’s three kinds of $()
1. $() can be $(expresion), that is, css selector, Xpath or html element, that is, through The above expression to match the target element.
2. $() can be $(element), which is a specific DOM element. For example, commonly used DOM objects include document, location, form, etc. For example, this line of code: The document in
$(document).find("div>p").html());
$() is a DOM element, that is, it searches for the dc6dce4a544fdca2df29d5ac0ea9906b element with e388a4556c0f65e1904146cc1a846bee in the full text, and displays the content in e388a4556c0f65e1904146cc1a846bee.
3. $() can be $(funcTIon), which is a function, which is a shorthand for $(document).ready(). For example, the common form is like this:
$(document).ready(funcTIon(){ alert("Hello world!"); });
Deformable operation:
$(function(){ alert("Hello world!"); });
The role of the $ symbol in jQuery
1. As a jQuery wrapper , use selectors to select DOM elements (this is also the most powerful function)
For example:
$("table tr:nth-child(even)")
2. Utility functions, as the namespace of several common utility functions Prefix
For example:
$.trim(someString)
3. Document ready handler, equivalent to $(document).ready(...)
For example:
$(function(){...}); //里面的函数会在DOM树加载完之后执行
4. Create DOM elements
For example:
$("<p>how are you?</p>")
5. Extend jQuery
For example:
$.fn.disable = function(){...}
6. Use jQuery and other libraries
For example: the Prototype library also uses the $ symbol. jQuery provides the noConflict function to avoid conflicts. jQuery.noConflict(); restores the $ symbol to the meaning defined by the non-jQuery library.
For more programming-related knowledge, please visit: Programming Learning Website! !
The above is the detailed content of What is the role of the $ symbol in jquery?. For more information, please follow other related articles on the PHP Chinese website!