Home >Web Front-end >JS Tutorial >What does $ mean in js
In JavaScript, the "$" symbol is a commonly used selector for selecting DOM elements. It represents the document root element, which is the entire HTML document.
To use the "$" symbol to select DOM elements, you can use the following syntax:
<code class="javascript">const element = $(selector);</code>
Where, selector
is A CSS selector that specifies the elements to select. For example, to select elements with the "container" class, you would use the following code:
<code class="javascript">const element = $('.container');</code>
The "$" symbol is often used with other JavaScript selectors, e.g. :
The main advantage of the "$" symbol is that it is shorter and easier to write than other selectors. It also works closely with the jQuery library, a popular DOM manipulation library in JavaScript.
Here are some examples of selecting DOM elements using the "$" symbol:
<code class="javascript">const header = $('#header');</code>
<code class="javascript">const paragraphs = $('p');</code>
<code class="javascript">const button = $('.btn:first');</code>
The above is the detailed content of What does $ mean in js. For more information, please follow other related articles on the PHP Chinese website!