Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

The role of the $ sign in jQuery

Posted on March 24, 2025March 24, 2025 by Zubair Shaik

Loading

The Role of the $ Sign in jQuery: A Comprehensive Guide


Introduction

When learning jQuery, one of the first things you encounter is the $ sign. In fact, the $ is synonymous with jQuery itself. This symbol, simple yet powerful, serves as the cornerstone of the jQuery library, making it accessible and easy to use.

What is the $ Sign in jQuery?

  • In jQuery, the $ sign is an alias for the jQuery function.
  • It is a shortcut used to access and manipulate HTML elements.
  • The primary syntax is: $(selector).action(); where:
    • $ is a shorthand for jQuery.
    • selector is used to select HTML elements.
    • action() defines the jQuery action or method to be applied to the selected elements.

Chapter 1: The Evolution and Purpose of the $ Sign

1. Origin of the $ Sign

  • The $ sign was chosen because it is concise, unique, and rarely used in traditional JavaScript.
  • jQuery, developed by John Resig in 2006, used the $ sign to differentiate itself from standard JavaScript functions.

2. The $ as an Alias

  • The $ is simply a shorthand for the jQuery() function.
  • The following two lines are identical: $("p").hide(); // Using $ jQuery("p").hide(); // Using jQuery

Chapter 2: The $ as a Function

1. The jQuery Function

  • The $ serves as a generic function that can be used to:
    • Select Elements
    • Create Elements
    • Manipulate the DOM
    • Handle Events
    • Perform AJAX Requests

2. Syntax Overview

$(selector).action();
  • Selector: Identifies the elements to be manipulated.
  • Action: Specifies the method to be executed on the selected elements.

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery $ Example</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $("p").css("color", "blue");
        });
    </script>
</head>
<body>
    <p>This paragraph text will turn blue.</p>
</body>
</html>
  • $(“p”) selects all paragraph elements.
  • css(“color”, “blue”) applies blue color styling.

Chapter 3: The $ as a Selector Engine

1. Selecting HTML Elements

The $ sign can select elements just like CSS selectors:

  • Element Selector: $("div").hide();
  • ID Selector: $("#uniqueId").show();
  • Class Selector: $(".className").css("color", "red");

2. Advanced Selectors

  • Attribute Selector: $("input[type='text']").val("Sample Text");
  • Hierarchical Selector: $("ul > li").css("background-color", "lightgray");

Chapter 4: The $ for DOM Manipulation

1. HTML and Text Manipulation

  • html() Method: Retrieves or sets HTML content. $("#example").html("<strong>New Content</strong>");
  • text() Method: Retrieves or sets plain text. $("#example").text("Plain Text");

2. Attribute Manipulation

$("img").attr("src", "newImage.jpg");

3. Adding and Removing Elements

  • append() and prepend(): Add content inside selected elements. $("ul").append("<li>New Item</li>"); $("ul").prepend("<li>First Item</li>");
  • before() and after(): Add content outside selected elements. $("p").before("<h2>Heading</h2>"); $("p").after("<div>Footer</div>");

Chapter 5: The $ for Event Handling

1. Event Handling Basics

$("#button").click(function() {
    alert("Button clicked!");
});
  • click(): Executes code when a click event occurs.
  • mouseover(), mouseout(), keydown(), focus() are other common events.

2. Event Binding with .on()

$("p").on("click", function() {
    $(this).css("color", "green");
});

Chapter 6: The $ for AJAX

1. Making AJAX Requests

$.ajax({
    url: "data.json",
    method: "GET",
    success: function(response) {
        console.log(response);
    },
    error: function() {
        alert("An error occurred.");
    }
});
  • The $ facilitates seamless AJAX calls, making dynamic data retrieval simple.

Chapter 7: Avoiding Conflicts with $

1. The noConflict() Method

  • If other JavaScript libraries use $, it can cause conflicts.
  • To avoid conflicts:
var jq = $.noConflict();
jq("p").css("color", "purple");
  • Here, jq is a substitute for $.

Chapter 8: The $ for Utility Functions

1. Iterating Over Elements

$.each([1, 2, 3], function(index, value) {
    console.log(index + ": " + value);
});

2. Checking Data Types

console.log($.isArray([1, 2, 3]));  // true
console.log($.isFunction(function() {}));  // true

Chapter 9: Practical Use Cases of the $ Sign

1. Form Validation

$("form").submit(function(event) {
    if ($("input").val() === "") {
        alert("Input cannot be empty!");
        event.preventDefault();
    }
});

2. Dynamic Styling

$(".change-style").click(function() {
    $("p").toggleClass("highlight");
});

Chapter 10: Common Mistakes with the $ Sign

1. Forgetting $(document).ready()

  • Ensures that the DOM is fully loaded before running scripts.
$(function() {
    // Correct way
    $("p").hide();
});

2. Confusion Between $ and jQuery

  • Remember that $ is an alias for jQuery.

  • The $ sign is the gateway to jQuery.
  • It simplifies the complex operations of traditional JavaScript.
  • From element selection to event handling, DOM manipulation, and AJAX requests, the $ symbol is versatile and powerful.
  • While jQuery’s popularity has declined due to modern frameworks, it remains a vital tool for quick and effective front-end development.

If there’s a specific aspect of the $ sign or jQuery you’d like to explore further, feel free to ask!

Posted Under jQueryAJAX with jQuery client-side scripting cross-browser compatibility CSS Manipulation Dollar Sign in jQuery DOM manipulation Dynamic Web Pages Element Selection event handling front-end development HTML Manipulation interactive web design JavaScript JavaScript Basics JavaScript frameworks JavaScript library jQuery jQuery $ jQuery Aliases jQuery Applications jQuery basics jQuery events jQuery examples jQuery Functions jQuery Introduction jQuery Learning jQuery methods jQuery noConflict jQuery selectors jQuery syntax jQuery tutorial jQuery Utility Functions UI Development Web Development web programming Web Technologies

Post navigation

Assigning Power BI Licenses using PowerShell
How jQuery simplifies JavaScript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions