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

What does $ mean in javascript

醉折花枝作酒筹
Release: 2021-04-16 18:16:18
Original
20019 people have browsed it

The meaning of "$" in JavaScript: 1. "$" can be used to represent variables, such as "var $s=wwd"; 2. In regular expressions, "$" represents the end of the matching string Position; 3. Use "$" to represent a function that searches for an object, instead of "document.getElementById".

What does $ mean in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer. The meaning of $ in

js is: The

$ symbol is a characteristic character representing variables in php. It also has many functions in js. Generally, we use it to name a function name and obtain the id. of.

1. First, it can be used to represent variables, such as variables var s='asdsd' or var $s='asdasd';

2. In regular expressions, it can match the end /sa$/.test(string) matches sa in the string string. For example, string='125sa' matches, string='125sa21' does not match. Regular expressions are very complicated, and here is just a brief explanation.

3. Due to the influence of prototype.js (a framework written by foreigners, used to encapsulate some commonly used functions for easy operation), many people now use $ to represent a function that finds an object, such as

$=function (id) {
  return (typeof (id)=='object')?id:document.getElementById(id);
};
Copy after login

In fact, it is a custom function. It is simple to use $. In fact, it is the same with other characters.

f=function (id) {
 return (typeof (id)=='object')?id:document.getElementById(id); 
};
Copy after login

The parameter id is the id in the html document, such as

then obj=$('ss') refers to the object with id='ss' that uses the $() method

$() method is used too frequently in the DOM A convenient shorthand for the document.getElementById() method, like this DOM method, this method returns the element with the id passed in as the parameter.

Compared with the methods in DOM, this is better. You can pass multiple ids as arguments and $() returns an Array object with all required elements.



 Test Page 





This is a paragraph

This is another paragraph



Copy after login

The above is the detailed content of What does $ mean in javascript. 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 [email protected]
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!