$() 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 <a/> 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 <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());
$() 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 <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());
$() is a DOM element, that is, it searches for the
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!"); });
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!