SlideShare a Scribd company logo
www.webstackacademy.com
DOM Handling
jQuery
www.webstackacademy.comwww.webstackacademy.com
DOM handling - jQuery
(Write less, Do more)
www.webstackacademy.com
Document Object Model (DOM)
• The W3C Document Object Model (DOM) is a platform and language-neutral interface
that allows programs and scripts to dynamically access and update the content,
structure, and style of a document
• jQuery provides multiple methods to manipulate DOM
• Using these methods it is easy to access and manipulate elements and attributes
• It also provides methods to change browser window dimensions
www.webstackacademy.com
DOM APIs
Selector Description
$(selector).text(); Sets or returns the text content of selected elements
$(selector).html(); Sets or returns the content of selected elements (including HTML mark-up)
$(selector).val(); Sets or returns the value of form fields
www.webstackacademy.com
Example usage – Getting values using DOM APIs
<script>
$(document).ready(function() {
/* Get values from various HTML elements */
$("#btn1").click(function(){
console.log("Paragraph" + $("#test1").text());
console.log("Value" + $("#test2").val());
});
});
</script>
www.webstackacademy.com
Example usage – Setting values using DOM APIs
<script>
$(document).ready(function() {
/* Upon button click change text */
$("#btn1").click(function(){
$("#test1").text("First paragraph - normal text");
});
/* Upon button click change HTML text */
$("#btn2").click(function(){
$("#test2").html("<b>Second paragraph</b>");
});
/* Upon button click change input field value */
$("#btn3").click(function(){
$("#test3").val("New Value...");
});
});
</script>
www.webstackacademy.com
DOM APIs – Insert and Remove
Selector Description
$(selector).append(); Inserts content at the end of the selected elements
$(selector).prepend(); Inserts content at the beginning of the selected elements
$(selector).after(); Inserts content after the selected elements
$(selector).before() Inserts content before the selected elements
$(selector).remove(); Removes the selected element (and its child elements)
$(selector).empty(); Removes the child elements from the selected element
www.webstackacademy.com
Example usage – Insert and remove using DOM APIs
<script>
$(document).ready(function() {
$("#myButton2").click(function(){
$("#test2").remove();
});
$("#myButton4").click(function(){
$("#test3").append(" <li><b>Appended text</b></li> ");
});
});
</script>
www.webstackacademy.com
DOM APIs – Handling styles
Selector & Description
$(selector).css("property", "value");
$(selector).css({"property": "value", "property": "value",....});
Set a single or multiple properties on a selector
$("p").css("background-color", "blue");
$("p").css({"background-color": "red", "font-size": "100%"});
www.webstackacademy.comwww.webstackacademy.com
Dimension APIs
(Write less, Do more)
www.webstackacademy.com
jQuery – Dimension APIs
Selector Description
$(selector).width(); Sets or returns the width of an element (excludes padding, border and
margin)
$(selector).height(); Sets or returns the height of an element (excludes padding, border and
margin).
$(selector).innerWidth(); Returns the width of an element (includes padding)
$(selector).innerHeight(); Returns the height of an element (includes padding)
$(selector).outerWidth(); Returns the width of an element (includes padding and border)
$(selector).outerHeight(); Returns the height of an element (includes padding and border)
www.webstackacademy.com
jQuery – Dimension APIs
www.webstackacademy.com
Example usage – Dimensions
<script>
$(document).ready(function() {
$("button").click(function(){
console.log("Width: " + $("#div1").width());
console.log("Height: " + $("#div1").height());
console.log("OuterWidth: " + $("#div1").outerWidth());
console.log("OuterHeight: " + $("#div1").outerHeight());
});
});
</script>
www.webstackacademy.comwww.webstackacademy.com
DOM Traversal - jQuery
(Write less, Do more)
www.webstackacademy.com
What is DOM traversal?
• DOM is organized in a tree structure where each node has parent and child nodes
• Typically leaf node contains the resource (ex: Text / Image etc..)
• jQuery offers multiple APIs to "traverse" (walk through) DOM tree by addressing using
relationships
• U can find / select single or multiple DOM nodes based on the selector tag provided to
jQuery
• Similar to other features (ex: effects), using jQuery DOM traversal can be done easily
www.webstackacademy.com
DOM Tree - Terminology
• To understand the tree structure and manipulate using jQuery few terminology need to
be understood with respect to a particular node
o Move up to find Ancestors
o Move down to find Descendants
o Move sideways to find Siblings
Element Relationship information
<div> Ancestor of all
<li> Parent of <span> child of <ul> and
descendant of <div>
<li><li> Siblings
www.webstackacademy.com
jQuery APIs - Traversing
Selector Description
$(selector).parent(); It returns the direct parent element of the selected element. By passing
an optional parameters it will return parents of that type (ex:
parent("ul"))
$(selector).parents(); It returns all ancestor elements of the selected element, all the way up to
the document's root element (<html>)
$(selector).parentsUntil(); The parentsUntil() method returns all ancestor elements between two
given arguments
Parents –
Traverse upwards
www.webstackacademy.com
Example usage – Parents Traversing
<script>
$(document).ready(function() {
/* Find parent of span element and change its attributes */
$("span").parent().css({"color": "red", "border": "2px solid red"});
/* Find all parents of span element all the way up-to HTML root */
$("span").parents().css({"color": "blue", "border": "2px solid blue"});
/* Filter parents that are only UL type */
$("span").parents("ul").css({"color": "green", "border": "2px solid green"});
/* Parent elements till DIV type */
$("span").parentsUntil("div").css({"color": "purple", "border": "2px solid
purple"});
});
</script>
www.webstackacademy.com
jQuery APIs - Descendants Traversing
Selector Description
$(selector).children(); It returns all direct children of the selected element. By passing an
optional parameter it will return children of particular type (ex:
children("p.first"))
$(selector).find(); It returns descendant elements of the selected element, all the way
down to the last descendant. By passing an optional parameter it will
return descendant of particular type (ex: find("span"))
Descendants –
Traverse downwards
www.webstackacademy.com
Example usage – Descendants Traversing
<script>
$(document).ready(function() {
/* Find children of div element and change its attributes */
$("div").children().css({"color": "red", "border": "2px solid red"});
/* Find children which are of particular class */
$("div").children("p.first").css({"color": "green", "border": "2px solid
green"});
/* Find a specific child */
$("div").find("span").css({"color": "purple", "border": "2px solid purple"});
/* Find all children */
$("div").find("*").css({"color": "pink", "border": "2px solid pink"});
});
</script>
www.webstackacademy.com
jQuery APIs - Siblings Traversing
Selector Description
$(selector).siblings(); It returns all sibling elements of the selected element
$(selector).next(); It returns the next sibling element of the selected element
$(selector).nextAll(); It returns all next sibling elements of the selected element
$(selector).nextUntil(); It returns all next sibling elements between two given arguments
$(selector).prev(); It returns the previous sibling element of the selected element
$(selector).prevAll(); It returns all next previous elements of the selected element
$(selector).prevUntil(); It returns all previous sibling elements between two given arguments
Siblings – Traverse
sideways
www.webstackacademy.com
Example usage – Siblings Traversing
<script>
$(document).ready(function() {
/* Find all siblings */
$("h2").siblings().css({"color": "red", "border": "2px solid red"});
/* Find children which are of particular type */
$("h2").siblings("p").css({"color": "green", "border": "2px solid green"});
/* Find the next sibling */
$("h2").next().css({"color": "purple", "border": "2px solid purple"});
});
</script>
www.webstackacademy.com
jQuery APIs - Filtering
Selector Description
$(selector).first(); It returns the first element of the specified elements
$(selector).last(); It returns the last element of the specified elements
$(selector).eq(); It returns an element with a specific index number of the selected elements
$(selector).filter(); It lets you specify a criteria. Elements that do not match the criteria are removed
from the selection, and those that match will be returned.
$(selector).not(); It returns all elements that do not match the criteria
www.webstackacademy.com
Example usage – Filtering
<script>
$(document).ready(function() {
/* Select first div type element and its children */
$("div").first().css("background-color", "yellow");
/* Select last div type element and its children */
$("div").last().css("background-color", "green");
});
</script>
www.webstackacademy.com
WebStack Academy
#83, Farah Towers,
1st Floor, MG Road,
Bangalore – 560001
M: +91-809 555 7332
E: training@webstackacademy.com
WSA in Social Media:

More Related Content

What's hot

Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Java script
Java scriptJava script
Java script
vishal choudhary
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Jussi Pohjolainen
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Sasidhar Kothuru
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
Karol Depka Pradzinski
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
rsnarayanan
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Jqueryppt (1)
Jqueryppt (1)Jqueryppt (1)
Jqueryppt (1)
AndreaSmile06
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
Natasha Murashev
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
itsarsalan
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
Artificial Intelligence Institute at UofSC
 
Jquery library
Jquery libraryJquery library
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
Sven Efftinge
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Seble Nigussie
 

What's hot (20)

Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Java script
Java scriptJava script
Java script
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Jqueryppt (1)
Jqueryppt (1)Jqueryppt (1)
Jqueryppt (1)
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
 
Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
 
Jquery library
Jquery libraryJquery library
Jquery library
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 

Similar to jQuery - Chapter 4 - DOM Handling

J query training
J query trainingJ query training
jQuery
jQueryjQuery
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
Denard Springle IV
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Gunjan Kumar
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
Mohammad Usman
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
Allegient
 
Jquery 2
Jquery 2Jquery 2
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
kolkatageeks
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Divakar Gu
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONS
RSolutions
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
J Query Public
J Query PublicJ Query Public
J Query Public
pradeepsilamkoti
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
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
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
azz71
 
jQuery
jQueryjQuery
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
Pradeep Saraswathi
 

Similar to jQuery - Chapter 4 - DOM Handling (20)

J query training
J query trainingJ query training
J query training
 
jQuery
jQueryjQuery
jQuery
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONS
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
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
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
jQuery
jQueryjQuery
jQuery
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 

More from WebStackAcademy

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 

More from WebStackAcademy (20)

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 

Recently uploaded

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
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
 
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
 
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
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
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
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
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
 
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
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 

Recently uploaded (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
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
 
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
 
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
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
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
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
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
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 

jQuery - Chapter 4 - DOM Handling

  • 3. www.webstackacademy.com Document Object Model (DOM) • The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document • jQuery provides multiple methods to manipulate DOM • Using these methods it is easy to access and manipulate elements and attributes • It also provides methods to change browser window dimensions
  • 4. www.webstackacademy.com DOM APIs Selector Description $(selector).text(); Sets or returns the text content of selected elements $(selector).html(); Sets or returns the content of selected elements (including HTML mark-up) $(selector).val(); Sets or returns the value of form fields
  • 5. www.webstackacademy.com Example usage – Getting values using DOM APIs <script> $(document).ready(function() { /* Get values from various HTML elements */ $("#btn1").click(function(){ console.log("Paragraph" + $("#test1").text()); console.log("Value" + $("#test2").val()); }); }); </script>
  • 6. www.webstackacademy.com Example usage – Setting values using DOM APIs <script> $(document).ready(function() { /* Upon button click change text */ $("#btn1").click(function(){ $("#test1").text("First paragraph - normal text"); }); /* Upon button click change HTML text */ $("#btn2").click(function(){ $("#test2").html("<b>Second paragraph</b>"); }); /* Upon button click change input field value */ $("#btn3").click(function(){ $("#test3").val("New Value..."); }); }); </script>
  • 7. www.webstackacademy.com DOM APIs – Insert and Remove Selector Description $(selector).append(); Inserts content at the end of the selected elements $(selector).prepend(); Inserts content at the beginning of the selected elements $(selector).after(); Inserts content after the selected elements $(selector).before() Inserts content before the selected elements $(selector).remove(); Removes the selected element (and its child elements) $(selector).empty(); Removes the child elements from the selected element
  • 8. www.webstackacademy.com Example usage – Insert and remove using DOM APIs <script> $(document).ready(function() { $("#myButton2").click(function(){ $("#test2").remove(); }); $("#myButton4").click(function(){ $("#test3").append(" <li><b>Appended text</b></li> "); }); }); </script>
  • 9. www.webstackacademy.com DOM APIs – Handling styles Selector & Description $(selector).css("property", "value"); $(selector).css({"property": "value", "property": "value",....}); Set a single or multiple properties on a selector $("p").css("background-color", "blue"); $("p").css({"background-color": "red", "font-size": "100%"});
  • 11. www.webstackacademy.com jQuery – Dimension APIs Selector Description $(selector).width(); Sets or returns the width of an element (excludes padding, border and margin) $(selector).height(); Sets or returns the height of an element (excludes padding, border and margin). $(selector).innerWidth(); Returns the width of an element (includes padding) $(selector).innerHeight(); Returns the height of an element (includes padding) $(selector).outerWidth(); Returns the width of an element (includes padding and border) $(selector).outerHeight(); Returns the height of an element (includes padding and border)
  • 13. www.webstackacademy.com Example usage – Dimensions <script> $(document).ready(function() { $("button").click(function(){ console.log("Width: " + $("#div1").width()); console.log("Height: " + $("#div1").height()); console.log("OuterWidth: " + $("#div1").outerWidth()); console.log("OuterHeight: " + $("#div1").outerHeight()); }); }); </script>
  • 15. www.webstackacademy.com What is DOM traversal? • DOM is organized in a tree structure where each node has parent and child nodes • Typically leaf node contains the resource (ex: Text / Image etc..) • jQuery offers multiple APIs to "traverse" (walk through) DOM tree by addressing using relationships • U can find / select single or multiple DOM nodes based on the selector tag provided to jQuery • Similar to other features (ex: effects), using jQuery DOM traversal can be done easily
  • 16. www.webstackacademy.com DOM Tree - Terminology • To understand the tree structure and manipulate using jQuery few terminology need to be understood with respect to a particular node o Move up to find Ancestors o Move down to find Descendants o Move sideways to find Siblings Element Relationship information <div> Ancestor of all <li> Parent of <span> child of <ul> and descendant of <div> <li><li> Siblings
  • 17. www.webstackacademy.com jQuery APIs - Traversing Selector Description $(selector).parent(); It returns the direct parent element of the selected element. By passing an optional parameters it will return parents of that type (ex: parent("ul")) $(selector).parents(); It returns all ancestor elements of the selected element, all the way up to the document's root element (<html>) $(selector).parentsUntil(); The parentsUntil() method returns all ancestor elements between two given arguments Parents – Traverse upwards
  • 18. www.webstackacademy.com Example usage – Parents Traversing <script> $(document).ready(function() { /* Find parent of span element and change its attributes */ $("span").parent().css({"color": "red", "border": "2px solid red"}); /* Find all parents of span element all the way up-to HTML root */ $("span").parents().css({"color": "blue", "border": "2px solid blue"}); /* Filter parents that are only UL type */ $("span").parents("ul").css({"color": "green", "border": "2px solid green"}); /* Parent elements till DIV type */ $("span").parentsUntil("div").css({"color": "purple", "border": "2px solid purple"}); }); </script>
  • 19. www.webstackacademy.com jQuery APIs - Descendants Traversing Selector Description $(selector).children(); It returns all direct children of the selected element. By passing an optional parameter it will return children of particular type (ex: children("p.first")) $(selector).find(); It returns descendant elements of the selected element, all the way down to the last descendant. By passing an optional parameter it will return descendant of particular type (ex: find("span")) Descendants – Traverse downwards
  • 20. www.webstackacademy.com Example usage – Descendants Traversing <script> $(document).ready(function() { /* Find children of div element and change its attributes */ $("div").children().css({"color": "red", "border": "2px solid red"}); /* Find children which are of particular class */ $("div").children("p.first").css({"color": "green", "border": "2px solid green"}); /* Find a specific child */ $("div").find("span").css({"color": "purple", "border": "2px solid purple"}); /* Find all children */ $("div").find("*").css({"color": "pink", "border": "2px solid pink"}); }); </script>
  • 21. www.webstackacademy.com jQuery APIs - Siblings Traversing Selector Description $(selector).siblings(); It returns all sibling elements of the selected element $(selector).next(); It returns the next sibling element of the selected element $(selector).nextAll(); It returns all next sibling elements of the selected element $(selector).nextUntil(); It returns all next sibling elements between two given arguments $(selector).prev(); It returns the previous sibling element of the selected element $(selector).prevAll(); It returns all next previous elements of the selected element $(selector).prevUntil(); It returns all previous sibling elements between two given arguments Siblings – Traverse sideways
  • 22. www.webstackacademy.com Example usage – Siblings Traversing <script> $(document).ready(function() { /* Find all siblings */ $("h2").siblings().css({"color": "red", "border": "2px solid red"}); /* Find children which are of particular type */ $("h2").siblings("p").css({"color": "green", "border": "2px solid green"}); /* Find the next sibling */ $("h2").next().css({"color": "purple", "border": "2px solid purple"}); }); </script>
  • 23. www.webstackacademy.com jQuery APIs - Filtering Selector Description $(selector).first(); It returns the first element of the specified elements $(selector).last(); It returns the last element of the specified elements $(selector).eq(); It returns an element with a specific index number of the selected elements $(selector).filter(); It lets you specify a criteria. Elements that do not match the criteria are removed from the selection, and those that match will be returned. $(selector).not(); It returns all elements that do not match the criteria
  • 24. www.webstackacademy.com Example usage – Filtering <script> $(document).ready(function() { /* Select first div type element and its children */ $("div").first().css("background-color", "yellow"); /* Select last div type element and its children */ $("div").last().css("background-color", "green"); }); </script>
  • 25. www.webstackacademy.com WebStack Academy #83, Farah Towers, 1st Floor, MG Road, Bangalore – 560001 M: +91-809 555 7332 E: training@webstackacademy.com WSA in Social Media: