J Query
J Query
library.
jQuery is cross-platform.
jQuery means "write less do more".
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. With a combination of versatility and
extensibility, jQuery has changed the way that
millions of people write JavaScript.
Download the jQuery library from jQuery.com
Include jQuery from a CDN, like Google
Download from
https://code.jquery.com/jquery-3.6.0.min.js
<head>
<script src="jquery-3.6.0.min.js"></script>
</head>
The jQuery CDN is a way to include jQuery in
your website without actually downloading and
keeping it your website's folder.
<head>
<script src="https://ajax.googleapis.com/ajax/
libs/jquery/3.6.0/jquery.min.js"></script>
</head>
Reduced server load
Faster content delivery(browser caching)
Constant availability
Better traffic management
Syntax → $(selector).action()
2 Tag ID
Represents a tag available with the given ID in the DOM. For
example $('#any-id') selects the single element in the
document that has an ID of any-id.
3 Tag Class
Represents a tag available with the given class in the DOM. For
example $('.any-class') selects all elements in the document
that have a class of any-class.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"
></script>
</head>
<body>
<h1>This is first paragraph.</h1>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("h1").css("font-size", "70px");
$("h1").css("color", "red");
});
</script>
</body>
</html>
jQuery DOM manipulation
text() - Sets or returns the text content of
selected elements
html() - Sets or returns the content of selected
elements (including HTML markup)
val() - Sets or returns the value of form fields
attr() - This method sets or returns attributes
and values of the selected elements.
slideUp()
slideToggle()
jQuery has the following fade methods:
fadeIn()
fadeOut()
fadeToggle()
fadeTo()