Day 20 - jQuery
jQuery
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
Installation
If you using package managers, you can install with this commands:
- npm:
npm install jquery
, - yarn:
yarn add jquery
.
More informations about downloading and installation you find at offical website
Simple examples
Find all divs and makes red border:
add()
function setBorder(){
$("div").css("border", "1px solid red");
}
Add class to the last paragraph p
on the site.
addClass()
function addClass(){
$("p").last().addClass("testClass");
}
Shorter version and add two classes:
function addClass(){
$( "p:last" ).addClass( "testClass highlight" );
}
More examples you can find in the offical documentation