Home > Article > Web Front-end > $. and $().Use case analysis
This time I will bring you $. and $(). use case analysis, what are the precautions for $. and $(). use case, the following is a practical case, let's 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 an html document, one of the function functions is to replace GetElementByID, but () can be not only ID, but also various selectors
For example:
$(document) That is to select the entire document object
Can we only use $ instead? No. In order to prevent naming conflicts, the jQuery library provides another mechanism to give other aliases to jQuery functions.
For example:
var jq = jQuery.noConflict(); // Do something with jQuery j("p p").hide(); // Do something with another library's $() $("content").style.display = 'none';
You can use jq instead of jQuery and $ in the code.
Let’s take a look at the use of $. and $() in jquery. There are What is the difference? What are their respective meanings?
$ is the jquery object, $() is jQuery(), you can pass parameters in it, and its function is to get the element
The following example
$(".p1") 表示获取类名为p1的元素,例如获取<p class="p1"></p> $(".p1").onclick表示类名为p1的p点击事件 jquery中$.,例如$.post(),$.get(),$.ajax()等这些都是jquery这个对象的方法
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
security.js RSA makes encryption function
How does Express test HTTPS locally
The above is the detailed content of $. and $().Use case analysis. For more information, please follow other related articles on the PHP Chinese website!