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:
$( ".select" );
document.querySelector( ".select" );
document.querySelectorAll( ".select" );
|
Some other examples of selectors:
To select the entire html:
To select the entire html body:
- In jQuery:
$("body")
- In JavaScript:
document.body
Class manipulation:
- Program:
$p.addClass(class-name)
p.classList.add(class-name)
|
Below some other examples of manipulation:
To add a class to an html element:
To remove a class to an html element:
To toggle a class to an html element:
To check whether an html element contains a class:
Event Listeners
- Program:
$( ".button" ).click( function (event) {
});
document.querySelector( ".button" )
.addEventListener( "click" , (event) => {
});
|
CSS Styling:
- Program:
$div.css({ margin: "10px" })
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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!