J Query
J Query
<head>
<script src="jquery-3.7.0.min.js"></script>
</head>
Include jQuery from a CDN
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.7.0/jquery.min.js"></
script>
</head>
Benefits of jQuery CDN
Reduced server load
Faster content delivery(browser caching)
Constant availability
Better traffic management
Syntax
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.
jQuery Example
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></
script>
</head>
<body>
<h1>This is first paragraph.</h1>
<script type="text/javascript">
$(document).ready(function(){
$("h1").css("font-size","70px");
$("h1").css("color","red");
});
</script>
</body>
</html>
jQuery DOM manipulation
jQuery get(to get or set content)
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
jQuery attr()
attr() - This method sets or returns attributes
and values of the selected elements.
elements
before() - Inserts content before the selected
elements
Removing content
To remove elements and content, there are
mainly two jQuery methods:
remove() - Removes the selected element
selected elements
removeClass() - Removes one or more classes from
slideUp()
slideToggle()
jQuery Effects
jQuery has the following fade methods:
fadeIn()
fadeOut()
fadeToggle()
fadeTo()