Jqueryin 38 BM
Jqueryin 38 BM
• 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.
• Short selectors
• Variety of animation functions
• Easy DOM traversing
• It helps us to manipulate HTML and CSS
• It helps us to manipulate DOM (Document Object Model) elements
• Provides event methods to trigger and respond to an events on a html page such as mouse click, keypress etc.
• Implements AJAX calls.
Example:
Java script DOM element access statement
Example:
• Download it from official website jQuery.com and host it on your server or local filesystem.
• Browser independent
• Wide range of plug-ins that allows developers to create plug-ins on top of the JavaScript library.
• Large development community.
• It is a lot easier to use compared to standard javascript and other javascript libraries.
• It lets users develop Ajax templates with ease. Ajax enables a sleeker interface where actions can
be performed on pages without requiring the entire page to be reloaded.
• Being Light weight and a powerful chaining capabilities makes it more strong.
• While jQuery has an impressive library in terms of quantity, depending on how much
customization you require on your website. The functionality may be limited thus using raw
javascript may be inevitable in some cases.
• The JQuery javascript file is required to run the commands, while the size of this file is relatively
small (25-100KB depending on the server). It is still a strain on the client computer and maybe
your web server as well if you intend to host the script on your own web server.
$(selector).action()
• A $ sign is to define/access jQuery
• A (selector) is to “query (or find)” HTML elements in html page
• A jQuery action() is the action to be performed on the selected element(s)
• jQuery selectors are used to select the HTML element(s) and allows you to manipulate the
HTML element(s) in a way we want. It selects the HTML elements on a variable parameter
such as their name, classes, id, types, attributes, attribute values, etc. All selectors in jQuery
are selected using a special sign i.e. dollar sign and parentheses:
• $("selector-name")
Method Description
Method Description
The first function is executed when the mouse enters the HTML
element, and the second function is executed when the mouse
leaves the HTML element
Prepared by: E.Swathi, Assistant Prof.,CSE,CBIT 16
Jquery Events
Method Description
On event: attaches one or more event handlers for the mouseleave: function(){
selected elements. $(this).css("background-color", "lightblue");
Example: },
<!DOCTYPE html> click: function(){
<html> $(this).css("background-color", "yellow");
<head> }
<script });
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/j });
query.min.js"></script> </script>
<script> </head>
$(document).ready(function(){ <body>
$("p").on({ <p>Click or move the mouse pointer over this paragraph.</p>
mouseenter: function(){ </body>
$(this).css("background-color", "lightgray"); </html>
},
• jQuery comes with a bunch of DOM related methods that make it easy to access and manipulate elements
and attributes.
• Three simple, but useful, jQuery methods for DOM manipulation are:
• jQuery has several methods for CSS manipulation. We will look at the following methods:
• addClass() - Adds one or more classes to the selected elements
• removeClass() - Removes one or more classes from the selected elements
• toggleClass() - Toggles between adding/removing classes from the selected elements
• css() - Sets or returns the style attribute
• https://learn.jquery.com/
• https://www.w3schools.com/jquery/default.asp
• https://www.tutorialspoint.com/jquery/index.htm
• https://www.javatpoint.com/jquery-tutorial