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

What's hot

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
manugoel2003
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Slashdot Tags
Slashdot TagsSlashdot Tags
Slashdot Tags
jamiemccarthy
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
Wildan Maulana
 
jQuery
jQueryjQuery
jQuery
Jay Poojara
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
Jquery
JqueryJquery
Jquery
Zoya Shaikh
 
jQuery
jQueryjQuery
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Bedis ElAchèche
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
Aaron Huang
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Marc Grabanski
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
orestJump
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
J query
J queryJ query
J query
Manav Prasad
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
Rod Johnson
 
jQuery
jQueryjQuery
J query1
J query1J query1
J query1
Manav Prasad
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Siva Arunachalam
 

What's hot (20)

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Slashdot Tags
Slashdot TagsSlashdot Tags
Slashdot Tags
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Jquery
JqueryJquery
Jquery
 
jQuery
jQueryjQuery
jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
J query
J queryJ query
J query
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery
jQueryjQuery
jQuery
 
J query1
J query1J query1
J query1
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 

Similar to Introduction to jQuery - The basics

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
Rakesh Jha
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
Allegient
 
JQuery
JQueryJQuery
jQuery
jQueryjQuery
JQuery
JQueryJQuery
JQuery
DevTalk
 
Jquery
JqueryJquery
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
iFour Institute - Sustainable Learning
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Gunjan Kumar
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Seble Nigussie
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
Lester Lievens
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
Salvatore Fazio
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
AditiPawale1
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
Umeshwaran V
 
jQuery
jQueryjQuery
jQuery
Vishwa Mohan
 
JQuery
JQueryJQuery
JQuery
JQueryJQuery
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
Hyeonseok Shin
 
jQuery
jQueryjQuery
J Query Public
J Query PublicJ Query Public
J Query Public
pradeepsilamkoti
 

Similar to Introduction to jQuery - The basics (20)

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
JQuery
JQueryJQuery
JQuery
 
jQuery
jQueryjQuery
jQuery
 
JQuery
JQueryJQuery
JQuery
 
Jquery
JqueryJquery
Jquery
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
jQuery
jQueryjQuery
jQuery
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
jQuery
jQueryjQuery
jQuery
 
J Query Public
J Query PublicJ Query Public
J Query Public
 

Recently uploaded

Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 

Recently uploaded (20)

Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 

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>