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

Detailed explanation of the use of $. and $(). in jQuery

php中世界最好的语言
Release: 2019-10-09 14:55:07
Original
8366 people have browsed it

This time I will bring you a detailed explanation of the use of $. and $(). in jQuery. What are the precautions for the use of $. and $(). in jQuery. The following is a practical case. Let’s take a look. take a look.

People like me who have not studied systematically always have this problem:(

$ is another name for jQuery

and jQuery is a function provided by the jQuery library .(It seems that it is not just a function, because there is also the use of $.ajax(options), which is equivalent to jQuery.ajax(options))

The function of this function is to search and sum based on the parameters in () To select elements in html documents, one of the function functions is to replace GetElementByID, but () can not only be ID, but also various class selectors

Related topic recommendations: "jQuery Tutorial"

For example:

$(document) is to select the entire document object

then Can you just use $ instead? No. In order to prevent naming conflicts, the jQuery library provides another mechanism to give jQuery functions another alias. For example:

var jq = jQuery.noConflict();
// Do something with jQuery
j("p p").hide();
// Do something with another library's $()
$("content").style.display = 'none';
Copy after login

can be used. jq is used instead of jQuery and $ in the code.

Let’s take a look at the difference between using $. and $(). in jquery and what are their respective meanings $ is the jquery object, $() is jQuery(), you can pass parameters in it, and the function is to get the element

The following example

$(".p1") 表示获取类名为p1的元素,例如获取<p class="p1"></p>
$(".p1").onclick表示类名为p1的p点击事件
jquery中$.,例如$.post(),$.get(),$.ajax()等这些都是jquery这个对象的方法
Copy after login

believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Using JQuery to operate Ajax (with case)


How to quickly operate JQuery elements

The above is the detailed content of Detailed explanation of the use of $. and $(). 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!