SlideShare ist ein Scribd-Unternehmen logo
1 von 21
HTML DOM & JQuery
“Less is more”
Compiled from Wikipedia.org, W3Schools.com & JQuery.com
by Abdul Hafeez
HTML DOM & JQuery : Agenda
• DOM – Document Object Model
• DOM History
• Node Document Tree
• Find & Access Nodes
• What is JQuery
• Why JQuery
• JQuery Philosophy
• How to assign events using JQuery
• Asynchronous Dynamic Fun
DOCUMENT OBJECT MODEL
• Platform and language independent standard object model for representing HTML or
XML related formats
• Level 1 DOM specification is published in 1998 by W3C, and it allowed to and
manipulation of every single element.
• No cross browser incompatibility
• DOM is the way JavaScript sees its containing HTML page
• DOM supports navigation in any direction
• SAX (Simple API for XML) is a popular alternative to the DOM
• DOM is separated in different parts
– Core
– XML
– HTML
• And into different levels, Level 1/2/3
HTML DOM
• Defines a standard way for accessing and manipulating
HTML documents
• Everything in an HTML document is a node.
– Document Node : Entire Document
– Element Node : HTML tags
– Text Node : Texts in element node
– Attribute Node : HTML attribute
– Comment Nodes
• DOM presents an HTML document as a tree structure (a node tree) with elements,
attributes and texts.
The tree starts at the document node and continues to branch out until it has reached
all text nodes at the lowest level.
• All the nodes in a node tree have relationships to each other (e.g. parent/child).
HTML DOM
Contd….
• With JavaScript we can restructure an entire HTML
document. We can add, remove, change or reorder
items on a page.
• To do so, JavaScript needs access to all elements in the
HTML document, and this access to the elements is
given through DOM.
HTML DOM
Contd….
Node/Document Tree
• All nodes have relationships to each other
• Except document node, every other node has a parent node
• Most element nodes have child nodes
• Nodes might share a parent and we call them siblings
• Nodes can also have descendants, meaning all the nodes that are children of a node,
or children of those children and so on.
• Nodes can also have ancestors. Ancestors are nodes that are parents of a node, or
parents of this parent and so on.
Find & Access Nodes
• JavaScript provides methods and properties to find and access nodes
• Using getElementById() and getElementByTagName() mothods
– It doesn’t follow document structure
– Can find any HTML element in the entire document.
– Gives us the HTML element(s) we need regardless of where they are in the document
– getElementByTagName(‘p’) gives us all the <p> elements in the document
– getElementById(‘RT’) returns the correct element whether it is hidden in the tree
• Using parentNode, firstChild and lastChild properties of an element node
– Follows document structure and allow short-distance travel in the document
What is jQuery
• An open source JavaScript library that simplifies the
interaction between HTML and JavaScript
• Is designed to change the way you write JavaScript
Why jQuery?
• Fully documented
• Great community
• Tons of plugins
• Small size (15kb)
• Everything works in IE 6+, Firefox, Safari 2+ and Opera
9+
• Simplifies how you handle events, perform animations or
add Ajax interactions
• And it is fast
• Can learn in 30 minutes
jQuery Philosophy
• (Almost) every operation boils down to:
– Find some stuff
– Do something to it
jQuery
• Select all <div> tags from the document
• document.getElementsByTagName(‘div’)
• jQuery(‘div’)
• $(‘div’)
• Select an element whose id is ‘DX’
• document.getElementById(‘DX’)
• $(‘#DX’)
• $(‘#DX’).hide(‘slow’)
jQuery
• Add a class (css) to all links in a document
• $(‘a’).addClass(‘cssURL’)
• Find all divs that do not have an id attribute
• $(‘div’).not(‘[@id]’)
• Find the fifth paragraph on the page, then find
the next element (its direct sibling)
• $(‘p’).eq(4).next()
Contd….
jQuery
• jQuery can take a snippet of HTML and it will
turn into a DOM element
• var div = $(‘<div>Dexter is in lab</div>’);
• div.addClass(‘cssDiv’);
• div.attr(‘id’,’DX’);
• Chaining
• var div = $(‘<div>text</div>’).addClass(‘cd’).attr(‘id’, ‘DX’);
• div.appendTo(‘div#FX’)
Contd….
jQuery
• Find this, do something
$(‘#DX’).show(‘medium’);
$(‘#FX’).addClass(‘css’);
• Chainable events: find this, do several things in
succession
$(‘#GX’).fadeIn(‘slow’).addClass(‘css’).html(‘Text’);
Contd….
How do you assign events?
• Don't add "onclick" to your markup: use jQuery to find
and assign events
$(‘#control’).click(function() {
$(‘#DX’).show().addClass(‘css’);
});
Asynchronous Dynamic Fun
• Asynchronous HTML and HTTP
$(‘#control’).click(function() {
$(‘#DX’).load(‘service.php’);
});
Asynchronous Dynamic Fun
• JSON Style (JavaScript Object Notation)
$(‘#control’).click(function() {
$.getJSON(‘service_json.php’, function(json)() {
alert(json);
});
});
• $.get( url, params, callback )
Load a remote page using an HTTP GET request.
• $.getScript( url, callback )
Loads and executes, a remote JavaScript file using an HTTP GET request.
• $.post( url, params, callback )
Load a remote page using an HTTP POST request.
Contd….
References
• http://www.jquery.com
• http://docs.jquery.com
• http://jquery.bassistance.de/api-browser
• http://www.learningjquery.com
• http://15daysofjquery.com
Q&A
Contact
Abdul Hafeez
habdul@in.com
http://in.linkedin.com/in/habdul
http://twitter.com/hafeez1216
http://drupal.coolpage.biz
http://drupal.org/user/315349

Weitere ähnliche Inhalte

Was ist angesagt?

Document Object Model
Document Object ModelDocument Object Model
Document Object Model
chomas kandar
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
thewarlog
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
Kostas Mavridis
 
A Short Tutorial to Semantic Media Wiki (SMW)
A Short Tutorial to Semantic Media Wiki (SMW) A Short Tutorial to Semantic Media Wiki (SMW)
A Short Tutorial to Semantic Media Wiki (SMW)
Jie Bao
 

Was ist angesagt? (20)

Dom structures
Dom structuresDom structures
Dom structures
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Document object model(dom)
Document object model(dom)Document object model(dom)
Document object model(dom)
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
 
INTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREEINTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREE
 
Drupal by fire
Drupal by fireDrupal by fire
Drupal by fire
 
Dom structure
Dom structureDom structure
Dom structure
 
Dom structure
Dom structure Dom structure
Dom structure
 
Introductory css and j query
Introductory css and j queryIntroductory css and j query
Introductory css and j query
 
Javascript libraries
Javascript librariesJavascript libraries
Javascript libraries
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
 
Dom structure
Dom structureDom structure
Dom structure
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Dom
DomDom
Dom
 
A Short Tutorial to Semantic Media Wiki (SMW)
A Short Tutorial to Semantic Media Wiki (SMW) A Short Tutorial to Semantic Media Wiki (SMW)
A Short Tutorial to Semantic Media Wiki (SMW)
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
J query
J queryJ query
J query
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Javascipt
JavasciptJavascipt
Javascipt
 

Ähnlich wie Html dom & j query

JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
Borey Lim
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
Mark Rackley
 

Ähnlich wie Html dom & j query (20)

FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQuery
 
Web technologies-course 09.pptx
Web technologies-course 09.pptxWeb technologies-course 09.pptx
Web technologies-course 09.pptx
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389 (1).ppt
6867389 (1).ppt6867389 (1).ppt
6867389 (1).ppt
 
Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)
 
Part 7
Part 7Part 7
Part 7
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
 
Jquery
JqueryJquery
Jquery
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Html dom & j query

  • 1. HTML DOM & JQuery “Less is more” Compiled from Wikipedia.org, W3Schools.com & JQuery.com by Abdul Hafeez
  • 2. HTML DOM & JQuery : Agenda • DOM – Document Object Model • DOM History • Node Document Tree • Find & Access Nodes • What is JQuery • Why JQuery • JQuery Philosophy • How to assign events using JQuery • Asynchronous Dynamic Fun
  • 3. DOCUMENT OBJECT MODEL • Platform and language independent standard object model for representing HTML or XML related formats • Level 1 DOM specification is published in 1998 by W3C, and it allowed to and manipulation of every single element. • No cross browser incompatibility • DOM is the way JavaScript sees its containing HTML page • DOM supports navigation in any direction • SAX (Simple API for XML) is a popular alternative to the DOM • DOM is separated in different parts – Core – XML – HTML • And into different levels, Level 1/2/3
  • 4. HTML DOM • Defines a standard way for accessing and manipulating HTML documents • Everything in an HTML document is a node. – Document Node : Entire Document – Element Node : HTML tags – Text Node : Texts in element node – Attribute Node : HTML attribute – Comment Nodes
  • 5. • DOM presents an HTML document as a tree structure (a node tree) with elements, attributes and texts. The tree starts at the document node and continues to branch out until it has reached all text nodes at the lowest level. • All the nodes in a node tree have relationships to each other (e.g. parent/child). HTML DOM Contd….
  • 6. • With JavaScript we can restructure an entire HTML document. We can add, remove, change or reorder items on a page. • To do so, JavaScript needs access to all elements in the HTML document, and this access to the elements is given through DOM. HTML DOM Contd….
  • 7. Node/Document Tree • All nodes have relationships to each other • Except document node, every other node has a parent node • Most element nodes have child nodes • Nodes might share a parent and we call them siblings • Nodes can also have descendants, meaning all the nodes that are children of a node, or children of those children and so on. • Nodes can also have ancestors. Ancestors are nodes that are parents of a node, or parents of this parent and so on.
  • 8. Find & Access Nodes • JavaScript provides methods and properties to find and access nodes • Using getElementById() and getElementByTagName() mothods – It doesn’t follow document structure – Can find any HTML element in the entire document. – Gives us the HTML element(s) we need regardless of where they are in the document – getElementByTagName(‘p’) gives us all the <p> elements in the document – getElementById(‘RT’) returns the correct element whether it is hidden in the tree • Using parentNode, firstChild and lastChild properties of an element node – Follows document structure and allow short-distance travel in the document
  • 9. What is jQuery • An open source JavaScript library that simplifies the interaction between HTML and JavaScript • Is designed to change the way you write JavaScript
  • 10. Why jQuery? • Fully documented • Great community • Tons of plugins • Small size (15kb) • Everything works in IE 6+, Firefox, Safari 2+ and Opera 9+ • Simplifies how you handle events, perform animations or add Ajax interactions • And it is fast • Can learn in 30 minutes
  • 11. jQuery Philosophy • (Almost) every operation boils down to: – Find some stuff – Do something to it
  • 12. jQuery • Select all <div> tags from the document • document.getElementsByTagName(‘div’) • jQuery(‘div’) • $(‘div’) • Select an element whose id is ‘DX’ • document.getElementById(‘DX’) • $(‘#DX’) • $(‘#DX’).hide(‘slow’)
  • 13. jQuery • Add a class (css) to all links in a document • $(‘a’).addClass(‘cssURL’) • Find all divs that do not have an id attribute • $(‘div’).not(‘[@id]’) • Find the fifth paragraph on the page, then find the next element (its direct sibling) • $(‘p’).eq(4).next() Contd….
  • 14. jQuery • jQuery can take a snippet of HTML and it will turn into a DOM element • var div = $(‘<div>Dexter is in lab</div>’); • div.addClass(‘cssDiv’); • div.attr(‘id’,’DX’); • Chaining • var div = $(‘<div>text</div>’).addClass(‘cd’).attr(‘id’, ‘DX’); • div.appendTo(‘div#FX’) Contd….
  • 15. jQuery • Find this, do something $(‘#DX’).show(‘medium’); $(‘#FX’).addClass(‘css’); • Chainable events: find this, do several things in succession $(‘#GX’).fadeIn(‘slow’).addClass(‘css’).html(‘Text’); Contd….
  • 16. How do you assign events? • Don't add "onclick" to your markup: use jQuery to find and assign events $(‘#control’).click(function() { $(‘#DX’).show().addClass(‘css’); });
  • 17. Asynchronous Dynamic Fun • Asynchronous HTML and HTTP $(‘#control’).click(function() { $(‘#DX’).load(‘service.php’); });
  • 18. Asynchronous Dynamic Fun • JSON Style (JavaScript Object Notation) $(‘#control’).click(function() { $.getJSON(‘service_json.php’, function(json)() { alert(json); }); }); • $.get( url, params, callback ) Load a remote page using an HTTP GET request. • $.getScript( url, callback ) Loads and executes, a remote JavaScript file using an HTTP GET request. • $.post( url, params, callback ) Load a remote page using an HTTP POST request. Contd….
  • 19. References • http://www.jquery.com • http://docs.jquery.com • http://jquery.bassistance.de/api-browser • http://www.learningjquery.com • http://15daysofjquery.com
  • 20. Q&A