Home > Web Front-end > JS Tutorial > What is the role of the $ symbol in jquery?

What is the role of the $ symbol in jquery?

青灯夜游
Release: 2020-11-20 15:18:30
Original
12012 people have browsed it

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());
Copy after login

$() is a DOM element, that is, it searches for the

element with

in the full text, and displays the content in

.

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!");
});
Copy after login

Deformable operation:

$(function(){
alert("Hello world!");
});
Copy after login

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)")
Copy after login

2. Utility functions, as the namespace of several common utility functions Prefix

For example:

$.trim(someString)
Copy after login

3. Document ready handler, equivalent to $(document).ready(...)

For example:

$(function(){...}); //里面的函数会在DOM树加载完之后执行
Copy after login

4. Create DOM elements

For example:

$("<p>how are you?</p>")
Copy after login

5. Extend jQuery

For example:

$.fn.disable = function(){...}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template