jQuery Selectors — The Absolute Basics

Transitioning from vanilla JavaScript to the jQuery library

Robbie Jaeger
Mar 17, 2017 · 3 min read

Beginning with Vanilla JavaScript

<h1>Hello jQuery!</h1><p class="intro-content">Let's use some selectors.</p>
document.querySelector("h1");
document.querySelector(".intro-content");

Transitioning to jQuery

<h1>Hello jQuery!</h1><p class="intro-content">Let's use some selectors.</p>
// Vanilla JavaScript
document.querySelector("h1");
// jQuery
$("h1");
// Vanilla JavaScript
document.querySelector(".intro-content");
// jQuery
$(".intro-content");

Return Values, Properties, and Methods

<h1>Hello jQuery!</h1><p class="intro-content">Let's use some selectors.</p>
document.querySelector("h1").innerText = "Changed Heading!";
$("h1").text("Changed Heading!");
// Vanilla JavaScript
document.querySelector("h1").innerText = "Changed Heading!";
// jQuery
$("h1").text("Changed Heading!");
$("h1").innerText = "Changed Heading!";
document.querySelector("h1").text("Changed Heading!");
Uncaught TypeError: document.querySelector(...).text is not a function

Additional Resources (Not the Absolute Basics)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store