javascript $ usage: 1. [$()] can be [$(expresion)], that is, css selector, Xpath or html element; 2. [$()] can be [$(element) 】, that is, a specific DOM element.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
javascript $ usage:
1. The meaning of $
The author of JS application library JQUERY uses $ as a Custom function name, this function is a function to obtain the specified web page element.
function $(Nid){ return document.getElementById(Nid); }
2. Simple usage
Here are three simple usage methods.
2.1, $(expresion)
$() can be $(expresion), that is, css selector, Xpath or html element, that is, through the above expression to match the target element.
2.2. $(element)
$() can be $(element), which is a specific DOM element. For example, commonly used DOM objects include document, location, form, etc.
2.3. $(function)
$() can be $(function), that is, a function, which is a member of $(document).ready() shorthand.
$(document).ready(function(){ alert("Hello world!"); });
can write:
$(function(){ alert("Hello world!"); });
Related free learning recommendations: javascript video tutorial
The above is the detailed content of What are the usages of javascript $. For more information, please follow other related articles on the PHP Chinese website!