Home > Web Front-end > JS Tutorial > body text

What is $() in jquery

coldplay.xixi
Release: 2023-01-04 09:37:05
Original
9469 people have browsed it

$() in jquery is: 1. [$()] can be [$(expresion)]; 2. [$()] can be [$(element)], that is, a specific DOM element; 3. [$()] can be [$(funcTIon)], which is a function.

What is $() in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, thinkpad t480 computer.

$() in jquery is:

1. $() can be $(expresion), that is, css selector, Xpath Or html element, that is, the target element is matched through the above expression.

For example: The object constructed by $("a") uses a CSS selector to construct a jQuery object - it selects all the <a/> tags. For example:

$("a").click(funcTIon(){...})
Copy after login

is the trigger event when any link on the page is clicked. To be precise, jQuery constructs an object $("a") using the tag <a/>, and the function click() is an (event) method of this jQuery object.

The following statement is used to operate this HTML:

alert($("div>p").html());
Copy after login

$() is a query expression, that is, use "div>p" like this A query expression constructs a jQuery object, and then "html()" means to display its html content, which is the [two] of the above HTML code snippet. Another example:

$("<div><p>Hello</p></div>").appendTo("body");
Copy after login

$() contains a string. Use such a string to construct a jQuery object, and then add this string to <body/> .

2. $() can be $(element), which is a specific DOM element.

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 this:

$(document).ready(funcTIon(){
alert("Hello world!");
});
Copy after login

Deformable operation:

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

Related free learning recommendations: javascript(Video)

The above is the detailed content of What is $() 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!