Home >Web Front-end >JS Tutorial >What is the dollar sign $ in js program_javascript skills
1. First of all, it can be used to represent variables,
For example, variable var s='asdsd' or var $s='asdasd';
2. In regular expressions, it can match the ending
/sa$ /.test(string)
Matches sa in the string string. For example, string='125sa' matches, string='125sa21' does not match.
Regular expressions are very complicated, 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 objects,
$=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); };
is actually a custom function, using $ is just simple, In fact, the same applies to other characters,
f=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); }; or
The parameter id is the id in the html document,
For example,