SlideShare a Scribd company logo
Introduction
to
jQuery
About jQuery
• jQuery is a JavaScript Library.
• jQuery simplifies JavaScript programming.
• jQuery is a lightweight, "write less, do more", JavaScript library
• The purpose of jQuery is to make it much easier to use JavaScript on
your website.
• jQuery was originally released in January 2006 at BarCamp NYC
by John Resig
How to use jQuery?
There are several ways to start using jQuery on your web site.
• Download the jQuery library from jQuery.com
• Include jQuery from a CDN, like Google
<head>
<script src="jquery-3.3.1.min.js"></script>
</head>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
jQuery Syntax
Basic syntax is: $(selector).action()
• A $ sign to define/access jQuery
• A (selector) to "query (or find)" HTML elements
• A jQuery action() to be performed on the element(s)
The Document Ready Event
$(document).ready(function(){
// jQuery methods go here...
});
$(function(){
// jQuery methods go here...
});
jQuery Selectors
Syntax Description
$("*") Selects all elements
$(this) Selects the current HTML element
$("p.intro") Selects all <p> elements with class="intro"
$("p:first") Selects the first <p> element
$("ul li:first") Selects the first <li> element of the first <ul>
$("ul li:first-child") Selects the first <li> element of every <ul>
$("[href]") Selects all elements with an href attribute
$("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"
$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"
$(":button") Selects all <button> elements and <input> elements of type="button"
$("tr:even") Selects all even <tr> elements
$("tr:odd") Selects all odd <tr> elements
Id Selector
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
Select First li from Groups
$(document).ready(function(){
$("button").click(function(){
$("ul li:first").hide();
});
});
Class Selector
$(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
Select all href Attributes
$(document).ready(function(){
$("button").click(function(){
$("[href]").hide();
});
});
Select First P from Groups
$(document).ready(function(){
$("button").click(function(){
$("p:first").hide();
});
});
Select even rows from a Table
$(document).ready(function(){
$("tr:even").css("background-
color", "yellow");
});
jQuery Event Methods
Mouse Events Keyboard Events Form Events Document/Window
Events
click keypress submit load
dblclick keydown change resize
mouseenter keyup focus scroll
mouseleave blur unload
$("p").click(function(){
$(this).hide();
});
$("#p1").mouseup(function(){
alert("Mouse up over p1!");
});
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
$("input").blur(function(){
$(this).css("background-
color", "#ffffff");
});
$("#p1").mouseleave(function(){
alert("Bye! You now leave p1!");
});
$("input").focus(function(){
$(this).css("background-color",
"#cccccc");
});
jQuery Effects
Hide & Show Effect
$("#hide").click(function(){
$("p").hide(); //.hide(1000); //.toggle();
});
$("#show").click(function(){
$("p").show();
});
FadeOut & FadeIn Effect
$("button").click(function(){
$("#div1").fadeIn(); //.fadeOut();//.fadeToggle();
$("#div2").fadeIn("slow"); //.fadeTo("slow", 0.5);
$("#div3").fadeIn(3000);
});
Slide up and Slide down Effect
$("#flip").click(function(){
$("#panel").slideDown();
});
$("#flip").click(function(){
$("#panel").slideToggle();
});
$("button").click(function(){
$("div").animate({
left: '250px',
opacity: '0.5',
height: '150px',
width: '150px'
});
});
jQuery - Get & Set
$(document).ready(function(){
$("button").click(function(){
alert($("#w3s").attr("href"));
});
});
<p><a href="https://www.w3schools.com"
id="w3s">W3Schools</a></p>
<button>Show href Value</button>
$(document).ready(function(){
$("#btn2").click(function(){
alert("HTML: " + $("#test").html() );
}); //.html("<b>Hello world!</b>");
});
<p id="test">This is some <b>bold</b> text in a
paragraph.</p>
<button id="btn2">Show HTML</button>
$(document).ready(function(){
$("#btn1").click(function(){
alert( $("#test").text() ); //.text(“setting the txt”);
});
})
<p id="test">This is some <b>bold</b> text in a
paragraph.</p>
<button id="btn1">Show Text</button>
$(document).ready(function(){
$("button").click(function(){
alert( $("#test").val() );
}); //.val(“Jquery is best");
});
<p>Name:
<input type="text" id="test" value="Mickey Mouse">
</p>
jQuery - Add & Remove
$("#div1").remove();
$("p").remove(".test");
$("p").remove(".test, .demo");
$("#div1").empty();
$("p").append("Some appended text.");
$("p").prepend("Some prepended text.");
$("img").after("Some text after");
$("img").before("Some text before");
jQuery - CSS Manipulation
$("button").click(function(){
$("p").toggleClass(“design");
});
$("p").css("background-color", "yellow");
$("p").css({"background-color": "yellow",
"font-size": “20px"});
.design {
font-weight: bold;
font-size: xx-large;
}
$("button").click(function(){
$("h1, h2, p").addClass("design");
//.addClass("important blue");
$("div").addClass(“design");
});
$("button").click(function(){
$("h2").removeClass(“design");
});
jQuery - Dimensions
jQuery has several important methods for working with dimensions:
• width()
• height()
• innerWidth()
• innerHeight()
• outerWidth()
• outerHeight()
$(document).ready(function(){
$("button").click(function(){
var msg = "";
msg += "Width of div: " + $("#div1").width() + "</br>";
msg += "Height of div: " + $("#div1").height() + "</br>";
msg += "Inner width of div: " + $("#div1").innerWidth() + "</br>";
msg += "Inner height of div: " + $("#div1").innerHeight();
$("#div1").html(msg );
});
});
<div style=“width:300px; height:100px; background:blue;” id="div1"></div>
<button>click me </button>

More Related Content

PPTX
jQuery Presentasion
PPTX
Angular 2.0 Views
PPTX
Jquery-overview
PPTX
jQuery quick tuts
PDF
Prototype & jQuery
PPTX
Jquery introduction
DOCX
Karan - form search
jQuery Presentasion
Angular 2.0 Views
Jquery-overview
jQuery quick tuts
Prototype & jQuery
Jquery introduction
Karan - form search

What's hot (20)

ODP
Introduction to jQuery
PPT
JQuery introduction
PDF
Slashdot Tags
PPTX
jQuery from the very beginning
PDF
Introducing jQuery
PPTX
jQuery
PPTX
jQuery Fundamentals
PPTX
Jquery
PPTX
PDF
jQuery Essentials
PDF
Dollar symbol
PDF
jQuery Essentials
PDF
Introduzione JQuery
PDF
Learning jQuery in 30 minutes
PPT
J query
PPTX
jQuery Presentation
PPT
PPTX
J query1
PDF
Pemrograman Web 8 - MySQL
PDF
jQuery for beginners
Introduction to jQuery
JQuery introduction
Slashdot Tags
jQuery from the very beginning
Introducing jQuery
jQuery
jQuery Fundamentals
Jquery
jQuery Essentials
Dollar symbol
jQuery Essentials
Introduzione JQuery
Learning jQuery in 30 minutes
J query
jQuery Presentation
J query1
Pemrograman Web 8 - MySQL
jQuery for beginners
Ad

Similar to Introduction to jQuery - The basics (20)

PPTX
Jquery Complete Presentation along with Javascript Basics
PDF
Advanced JQuery Mobile tutorial with Phonegap
PDF
jQuery Rescue Adventure
PPTX
PDF
PPTX
JQuery
PPTX
PPTX
jQuery for web development
PPTX
Introduction to jQuery
PDF
Introduction to jQuery
KEY
jQuery - Tips And Tricks
PPTX
Jquery fundamentals
PPTX
JQuery_and_Ajax.pptx
PPTX
Jquery Basics
PPTX
jQuery
PDF
jQuery Basic API
PPTX
PPT
J Query Public
Jquery Complete Presentation along with Javascript Basics
Advanced JQuery Mobile tutorial with Phonegap
jQuery Rescue Adventure
JQuery
jQuery for web development
Introduction to jQuery
Introduction to jQuery
jQuery - Tips And Tricks
Jquery fundamentals
JQuery_and_Ajax.pptx
Jquery Basics
jQuery
jQuery Basic API
J Query Public
Ad

Recently uploaded (20)

PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Assigned Numbers - 2025 - Bluetooth® Document
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Advanced methodologies resolving dimensionality complications for autism neur...
The Rise and Fall of 3GPP – Time for a Sabbatical?

Introduction to jQuery - The basics

  • 2. About jQuery • jQuery is a JavaScript Library. • jQuery simplifies JavaScript programming. • jQuery is a lightweight, "write less, do more", JavaScript library • The purpose of jQuery is to make it much easier to use JavaScript on your website. • jQuery was originally released in January 2006 at BarCamp NYC by John Resig
  • 3. How to use jQuery? There are several ways to start using jQuery on your web site. • Download the jQuery library from jQuery.com • Include jQuery from a CDN, like Google <head> <script src="jquery-3.3.1.min.js"></script> </head> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head>
  • 4. jQuery Syntax Basic syntax is: $(selector).action() • A $ sign to define/access jQuery • A (selector) to "query (or find)" HTML elements • A jQuery action() to be performed on the element(s) The Document Ready Event $(document).ready(function(){ // jQuery methods go here... }); $(function(){ // jQuery methods go here... });
  • 5. jQuery Selectors Syntax Description $("*") Selects all elements $(this) Selects the current HTML element $("p.intro") Selects all <p> elements with class="intro" $("p:first") Selects the first <p> element $("ul li:first") Selects the first <li> element of the first <ul> $("ul li:first-child") Selects the first <li> element of every <ul> $("[href]") Selects all elements with an href attribute $("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank" $("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank" $(":button") Selects all <button> elements and <input> elements of type="button" $("tr:even") Selects all even <tr> elements $("tr:odd") Selects all odd <tr> elements
  • 6. Id Selector $(document).ready(function(){ $("button").click(function(){ $("#test").hide(); }); }); Select First li from Groups $(document).ready(function(){ $("button").click(function(){ $("ul li:first").hide(); }); }); Class Selector $(document).ready(function(){ $("button").click(function(){ $(".test").hide(); }); }); Select all href Attributes $(document).ready(function(){ $("button").click(function(){ $("[href]").hide(); }); }); Select First P from Groups $(document).ready(function(){ $("button").click(function(){ $("p:first").hide(); }); }); Select even rows from a Table $(document).ready(function(){ $("tr:even").css("background- color", "yellow"); });
  • 7. jQuery Event Methods Mouse Events Keyboard Events Form Events Document/Window Events click keypress submit load dblclick keydown change resize mouseenter keyup focus scroll mouseleave blur unload $("p").click(function(){ $(this).hide(); }); $("#p1").mouseup(function(){ alert("Mouse up over p1!"); }); $("#p1").mouseenter(function(){ alert("You entered p1!"); }); $("input").blur(function(){ $(this).css("background- color", "#ffffff"); }); $("#p1").mouseleave(function(){ alert("Bye! You now leave p1!"); }); $("input").focus(function(){ $(this).css("background-color", "#cccccc"); });
  • 8. jQuery Effects Hide & Show Effect $("#hide").click(function(){ $("p").hide(); //.hide(1000); //.toggle(); }); $("#show").click(function(){ $("p").show(); }); FadeOut & FadeIn Effect $("button").click(function(){ $("#div1").fadeIn(); //.fadeOut();//.fadeToggle(); $("#div2").fadeIn("slow"); //.fadeTo("slow", 0.5); $("#div3").fadeIn(3000); }); Slide up and Slide down Effect $("#flip").click(function(){ $("#panel").slideDown(); }); $("#flip").click(function(){ $("#panel").slideToggle(); }); $("button").click(function(){ $("div").animate({ left: '250px', opacity: '0.5', height: '150px', width: '150px' }); });
  • 9. jQuery - Get & Set $(document).ready(function(){ $("button").click(function(){ alert($("#w3s").attr("href")); }); }); <p><a href="https://www.w3schools.com" id="w3s">W3Schools</a></p> <button>Show href Value</button> $(document).ready(function(){ $("#btn2").click(function(){ alert("HTML: " + $("#test").html() ); }); //.html("<b>Hello world!</b>"); }); <p id="test">This is some <b>bold</b> text in a paragraph.</p> <button id="btn2">Show HTML</button> $(document).ready(function(){ $("#btn1").click(function(){ alert( $("#test").text() ); //.text(“setting the txt”); }); }) <p id="test">This is some <b>bold</b> text in a paragraph.</p> <button id="btn1">Show Text</button> $(document).ready(function(){ $("button").click(function(){ alert( $("#test").val() ); }); //.val(“Jquery is best"); }); <p>Name: <input type="text" id="test" value="Mickey Mouse"> </p>
  • 10. jQuery - Add & Remove $("#div1").remove(); $("p").remove(".test"); $("p").remove(".test, .demo"); $("#div1").empty(); $("p").append("Some appended text."); $("p").prepend("Some prepended text."); $("img").after("Some text after"); $("img").before("Some text before");
  • 11. jQuery - CSS Manipulation $("button").click(function(){ $("p").toggleClass(“design"); }); $("p").css("background-color", "yellow"); $("p").css({"background-color": "yellow", "font-size": “20px"}); .design { font-weight: bold; font-size: xx-large; } $("button").click(function(){ $("h1, h2, p").addClass("design"); //.addClass("important blue"); $("div").addClass(“design"); }); $("button").click(function(){ $("h2").removeClass(“design"); });
  • 12. jQuery - Dimensions jQuery has several important methods for working with dimensions: • width() • height() • innerWidth() • innerHeight() • outerWidth() • outerHeight() $(document).ready(function(){ $("button").click(function(){ var msg = ""; msg += "Width of div: " + $("#div1").width() + "</br>"; msg += "Height of div: " + $("#div1").height() + "</br>"; msg += "Inner width of div: " + $("#div1").innerWidth() + "</br>"; msg += "Inner height of div: " + $("#div1").innerHeight(); $("#div1").html(msg ); }); }); <div style=“width:300px; height:100px; background:blue;” id="div1"></div> <button>click me </button>