Home > Article > Web Front-end > What is $() in jquery
$() 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.
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 7d01d0a03a49fceb57d12197d8d196cb tags. For example:
$("a").click(funcTIon(){...})
is the trigger event when any link on the page is clicked. To be precise, jQuery constructs an object $("a") using the tag 7d01d0a03a49fceb57d12197d8d196cb
, 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());
$() 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");
$() contains a string. Use such a string to construct a jQuery object, and then add this string to b2636b4e0e32f7cd731b9073897693b7
.
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());
$() 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 this:
$(document).ready(funcTIon(){ alert("Hello world!"); });
Deformable operation:
$(function(){ alert("Hello world!"); });
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!