Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
jQuery Core & DOM Manipulation 12 mins read Free Lesson

jQuery Syntax, $(document).ready() & Selectors

Understand the jQuery wrapper $(), document ready event, element, class, ID, and attribute selectors.

jQuery Syntax & Selectors

The basic syntax is: $(selector).action()

// Ensure DOM is fully loaded before running script
$(document).ready(function() {
    // Hide all paragraphs when clicking a button
    $("button").click(function() {
        $("p.alert").hide();
    });
});

Common Selectors:

  • $("#header"): Selects single element with ID 'header'.
  • $(".card"): Selects all elements with class 'card'.
  • $("ul li:first-child"): Selects the first list item of every list.