agyanadda@gmail.com

jQuery vs JavaScript

jQuery Projects and Best Practices 1 min read Updated Dec 1, 2026 Topic 24 of 25

Modern JavaScript can do most jQuery tasks. Knowing both helps you read old code and write new code.

Task jQuery Vanilla JavaScript
Select $('.card') document.querySelectorAll('.card')
Ready $(fn) document.addEventListener('DOMContentLoaded', fn)
Click $('#b').on('click', fn) b.addEventListener('click', fn)
Text $('#t').text('Hi') t.textContent = 'Hi'
Class $('#t').addClass('on') t.classList.add('on')
Toggle $('#t').toggleClass('on') t.classList.toggle('on')
Hide $('#t').hide() t.hidden = true
Attribute $('a').attr('href') a.getAttribute('href')
AJAX $.getJSON(url) fetch(url).then(r => r.json())

When jQuery still makes sense

  • The project already uses it (WordPress, older Laravel or PHP apps)
  • You rely on jQuery plugins like DataTables or Select2
  • Quick effects like slideToggle() with one line

When to skip it

  • New projects with modern browsers
  • React, Vue or Angular apps (they manage the DOM themselves)
  • Performance-critical pages where every KB matters (jQuery is about 30 KB gzipped)

Example

Example — Same feature, two ways HTML
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<style>.on{background:#1f386b;color:#fff}</style>

<button id="jq">jQuery button</button>
<button id="js">JavaScript button</button>
<p id="out"></p>

<script>
  // jQuery version
  $(function () {
    $('#jq').on('click', function () {
      $(this).toggleClass('on');
      $('#out').text('Toggled with jQuery');
    });
  });

  // Vanilla JavaScript version
  document.addEventListener('DOMContentLoaded', function () {
    document.getElementById('js').addEventListener('click', function () {
      this.classList.toggle('on');
      document.getElementById('out').textContent = 'Toggled with vanilla JavaScript';
    });
  });
</script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

What is the vanilla JavaScript version of $('#t').addClass('on')?

Exercise 2 True / False

React apps usually use jQuery to update the DOM.

Exercise 3 Fill in the Blank

The modern JavaScript replacement for $.getJSON is ___().

Frequently Asked Questions

Yes. jQuery is JavaScript. Get a plain element from a jQuery object with $('#box')[0] or $('#box').get(0).