Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

What does dollar sign ($) means in jQuery ?

  • Last Updated : 19 Jul, 2021

The $ sign is nothing but an identifier of jQuery() function. 

Instead of writing jQuery we simply write $ which is the same as jQuery() function. A $ with a selector specifies that it is a jQuery selector. It is given a shorter identifier as $ just to reduce the time for writing larger syntax. It contains all the functions that are used by a jQuery object such as animate(), hide(), show(), css() and many more. Moreover, in terms of memory, $ is better than jQuery because $ takes a byte and jQuery takes 6 bytes which have the same functionality. 

Syntax:

$('selector').action();

Example 1: A simple illustration to show jQuery and $ have the same functionality.

HTML




!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    
    <!-- Including jQuery  -->
            integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
            crossorigin="anonymous">
    </script>
</head>
  
<body>    
    <script>
       console.log($===jQuery)
    </script>
</body>
  
</html>

Output:



true

Note: $(‘p’) and jQuery(‘p’) have the same meaning, and they return the same objects.

Example 2:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
      
    <!-- Including jQuery  -->
            integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
            crossorigin="anonymous">
   </script>
</head>
  
<body>
    <p> This is a paragraph</p>
    <script>
      var p = $('p').text();
      var x = jQuery('p').text()
      console.log(p);
      console.log(x);
    </script>
</body>
</html>

Output:

We can even change the $ by using jQuery noConflict() function because there may be chances when we are using other technologies which may have different meaning, in such cases we can have our customized identifier for jQuery using noConflict() method.

Syntax:

var new_identifier = jQuery.noConflict();

Example 3:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    
    <!-- Including jQuery  -->
            integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
            crossorigin="anonymous">
    </script>
</head>
  
<body>
      
<p> This is a paragraph</p>
  
    <script>
      var dollar =  jQuery.noConflict();
  
      // We can use dollar instead of $ by 
      // using jQuery noConflict() method
      var x = dollar('p').text()
      console.log(x);
    </script>
</body>
  
</html>

Output:

This is a paragraph



My Personal Notes arrow_drop_up
Recommended Articles
Page :