1. The meaning of $ symbol in JS [Indicates variables] For example, variable var s='asdsd' or var $s='asdasd';
[Match the end, in regular expressions] /sa$/.test(string) matches sa in the string string. For example, string='125sa' matches, string='125sa21' does not match.
[Represents a function to find objects]
$=function (id) {
return (typeof (id)=='object') ?id:document.getElementById(id); };
is actually a custom function. It’s just simple to use $, but it’s the same with other characters,
f=function (id) {
return (typeof (id)=='object')?id:document.getElementById (id); };
You can also use the parameter id to be the id in the html document, such as
Then obj=$('ss') is The referenced object with id='ss' uses the $() method
The $() method is a convenient shorthand for the document.getElementById() method that is used too frequently in the DOM, just like this DOM method, this The method returns the element with the id passed in as the parameter. This is better than the method in DOM. You can pass multiple ids as arguments and $() returns an Array object with all required elements.
2. The meaning of the # symbol in JS This #XXXX represents the id of a certain HTML element. This is based on the selector of css. In css, #xxx means the specified Element ID to find elements Generally, HTML elements define their id through the id attribute. For example,
The ID here is mydiv, used above The function is $("#mydiv"); and $(xxx) should be the jQuery code, used to return the element specified by xxx, where XXX is compatible with the css selector