Home  >  Article  >  Web Front-end  >  Analysis of the role of $ symbol in jQuery

Analysis of the role of $ symbol in jQuery

不言
不言Original
2018-07-14 16:41:251597browse

This article mainly introduces the analysis of the role of the $ symbol in jQuery. It has a certain reference value. Now I share it with you. Friends in need can refer to it

$ symbol overall It has two functions:

1. Called as a general function: $(param)

(1), the parameter is a function: When the DOM is loaded, execute this callback function

 $(function(){//Execute after the DOM is loaded

  //Code

 })

(2), the parameter is the selector string: find all matching tags and encapsulate them into jQuery objects

(3). The parameter is a dom object: encapsulate the dom object into a jQuery object

such as: $(this)

Note: The difference between jQuery objects and dom objects:

jQuery objects can use jQuery methods, but dom objects cannot!

 $("li")[0] is a dom object, and then wrapped by $() $($("li")[0] ) returns a jQuery object, then You can use jQuery method

(4), the parameter is html tag string (less used): create a tag object and encapsulate it into a jQuery object

2. Use as an object: $.xxx()

Such as:

(1) $.each(): Traverse the array Or object

(2) $.trim(): Remove the spaces at both ends

The above is the entire content of this article, I hope it will be useful for everyone’s learning Help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

How to use jquery to implement a sixty-second countdown

Analysis of DOM objects in JavaScript

Analysis of how NodeJS operates message queue RabbitMQ

The above is the detailed content of Analysis of the role of $ symbol in jQuery. For more information, please follow other related articles on the PHP Chinese website!

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