How to convert jQuery to JavaScript ?

03 Aug, 2021
JavaScript is an object orient programming language designed to make web development easier and more attractive. In most cases, JavaScript is used to create responsive, interactive elements for web pages, enhancing the user experience.
jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript.
Selection: In jQuery, to select any element, we simply use the $() sign, but in JavaScript, to select any element, we can use querySelector() or querySelectorAll().
Program:// jQuery to select all instances// of class "select"$(".select");  // JavaScript to select only the// first instance of class "select"document.querySelector(".select");  // To select all the instances// of class "select"  document.querySelectorAll(".select");
// jQuery to select all instances// of class "select"$(".select");  // JavaScript to select only the// first instance of class "select"document.querySelector(".select");  // To select all the instances// of class "select"  document.querySelectorAll(".select");
Some other examples of selectors:
To select the entire html:
In jQuery:$("html")
$("html")
In JavaScript:document.querySelector(selector)
document.querySelector(selector)
To select the entire html body:
In jQuery:$("body")
$("body")
In JavaScript:document.body
document.body
Class manipulation:
Program:// To add a class "class-name" to a <p> tag// jQuery:$p.addClass(class-name)   // JavaScript:p.classList.add(class-name)
// To add a class "class-name" to a <p> tag// jQuery:$p.addClass(class-name)   // JavaScript:p.classList.add(class-name)
Below some other examples of manipulation:
To add a class to an html element:
In jQuery:$element.addClass(class-name)
$element.addClass(class-name)
In JavaScript:element.classList.add(class-name)
element.classList.add(class-name)
To remove a class to an html element:
In jQuery:$element.removeClass(class-name)
$element.removeClass(class-name)
In JavaScript:element.classList.remove(class-name)
element.classList.remove(class-name)
To toggle a class to an html element:
In jQuery:$element.toggleClass(class-name)
$element.toggleClass(class-name)
In JavaScript:element.classList.toggle(class-name)
element.classList.toggle(class-name)
To check whether an html element contains a class:
In jQuery:$element.hasClass(class-name)
$element.hasClass(class-name)
In JavaScript:element.classList.has(class-name)
element.classList.has(class-name)
Event Listeners
Program:// To add an event on button click   // jQuery:/* handle click event */  $(".button").click( function(event) { });  // JavaScript:/* handle click event */  document.querySelector(".button")    .addEventListener("click", (event) => {});
// To add an event on button click   // jQuery:/* handle click event */  $(".button").click( function(event) { });  // JavaScript:/* handle click event */  document.querySelector(".button")    .addEventListener("click", (event) => {});
CSS Styling:
Program:// To give a margin of 10px to all the div// jQuery:$div.css({ margin: "10px" })   // JavaScript:div.style.margin= "10px"
// To give a margin of 10px to all the div// jQuery:$div.css({ margin: "10px" })   // JavaScript:div.style.margin= "10px"
jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it’s philosophy of “Write less, do more”.You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.
JavaScript-Misc
jQuery-Misc
JavaScript
JQuery
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.