jQuery vs Modern JavaScript

The vanilla equivalents.

✍️ 3 exercises + code challenge in this lesson

Today's browsers support everything jQuery was created for. Knowing both helps when maintaining older projects:

  • $("#id") → document.querySelector("#id")
  • $(".x").addClass("y") → document.querySelectorAll(".x").forEach(el => el.classList.add("y"))
  • .on("click", fn) → addEventListener("click", fn)
  • .text("hi") → textContent = "hi"
  • $.getJSON(url) → fetch(url).then(r => r.json())
  • .fadeIn() → CSS transitions

Key Takeaways: jQuery vs Modern JavaScript

Mastering jQuery vs Modern JavaScript helps you write clean and reliable jQuery code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

jQuery vs Modern JavaScript Code Example

jQuery
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

<p id="a">jQuery</p>
<p id="b">Vanilla JS</p>

<script>
  // jQuery
  $("#a").css("color", "#0769AD").on("click", () => alert("jQuery click"));

  // Same thing in modern JavaScript
  const b = document.querySelector("#b");
  b.style.color = "#EAB308";
  b.addEventListener("click", () => alert("Vanilla click"));
</script>
Free sign-in required · Google login available

jQuery vs Modern JavaScript Practice Exercises

Check what you learned in “jQuery vs Modern JavaScript”.

/ 3 solved
Fill in the blank

The vanilla equivalent of $("#id").

document.("#id")
✓ Correct! Not quite. Try again.
Multiple choice

What is the vanilla equivalent of $.getJSON(url)?

✓ Correct! Not quite. Try again.
Code challenge

Without jQuery, set the text of #out to "Vanilla!" using document.querySelector.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services