SlideShare a Scribd company logo
6
Most read
11
Most read
19
Most read
DOM(DOCUMENT OBJECT
MODEL)
PRESENTED BY: NABIN JAMKATEL
INTRODUCTION
• JavaScript arranges objects in a Document Object Model or
DOM.
• The DOM defines the logical structure of objects and the way
an object is accessed and manipulated.
• The document object model can be thought of as a hierarchy
moving from the most general object to the most specific.
• The HTML DOM defines a standard set of objects for HTML,
and a standard way to access and manipulate HTML
documents
• All HTML elements, along with their containing text
and attributes, can be accessed through the DOM.
• The contents can be modified or deleted, and new
elements can be created.
• The HTML DOM is platform and language
independent
DOCUMENT OBJECT MODEL
HTML DOM OBJECTS
• Anchor object
• Document object
• Event object
• Form and Form Input object
• Frame, Frameset, and IFrame objects
• Image object etc
DOM HIERARCHY
• The topmost object in the hierarchy is the window
object, which contains the other objects in the list, such
as the current frame, history list, and the Web page
document.
• The Web page document contains its own set of
objects, including links, anchors, and forms.
• Within each form are form objects, such as input boxes,
radio buttons, or selection lists.
MANAGING EVENTS
• An event is a specific occurrence within the Web browser.
For example:
• opening up a Web page
• positioning the mouse pointer over a location on that page
• Events are an important part of JavaScript programming,
you can write scripts that run in response to the actions
of the user, even after the Web page has been opened.
ONLOAD & ONUNLOAD
<html>
<head>
<title>Hello/Goodbye page</title>
<script type="text/javascript">
function Hello()
{ globalName=prompt("Welcome to my page. " + "What is your
name?","");
}
function Goodbye() {
alert("So long, " + globalName + ome back real soon.");
}
</script>
</head>
<body onload="Hello();" onunload="Goodbye();">
<p>Whatever text appears in the page.</p>
</body>
</html>
USING THE ONCLICK EVENT HANDLER
WINDOWS EXAMPLE
<html>
<head>
<title> Fun with Buttons </title>
<script type="text/javascript">
function Help(){
var OutputWindow =
window.open("", "",
"status=0,menubar=0,height=200,width=200");
OutputWindow.document.open();
• OutputWindow.document.write("This might be a context-" +
• "sensitive help message, depending on the " +
• "application and state of the page.");
• }
• </script>
• </head>
• <body>
• <form id="ButtonForm">
• <p> <input type="button" value="Click for Help"
• onclick="Help();" /> </p>
• </form>
• </body>
• </html>
EVENTS INITIATED BY THE USER DURING
DATA ENTRY
GETELEMENTBYID()
<html>
<head>
<script type="text/javascript">
function getElement() {
var x=document.getElementById("myHeader");
alert("I am a " + x.tagName + " element"); }
</script>
</head>
<body>
<h1 id="myHeader" onclick="getElement()">Click to see what element I
am!</h1>
</body>
GETELEMENTSBYNAME()
<html>
<head>
<script type="text/javascript">
function getElements() {
var x=document.getElementsByName("myInput")
alert(x.length + " elements!")
}
</script>
</head>
<body>
<input name="myInput" type="text" size="20"><br />
<input name="myInput" type="text" size="20"><br />
<input name="myInput" type="text" size="20"><br />
<br />
<input type="button" onclick="getElements()" value="How many elements
named
'myInput'?">
</body>
</html>
RETURN THE INNERHTML OF THE FIRST ANCHOR
IN A DOCUMENT
<html>
<body>
<a name="first">First anchor</a><br />
<a name="second">Second anchor</a><br />
<a name="third">Third anchor</a><br />
<br />
InnerHTML of the first anchor in this document:
<script type="text/javascript">
document.write(document.anchors[0].innerHTML)
</script>
</body>
</html>
ACCESS AN ITEM IN A COLLECTION
<html>
<body>
<form id="Form1" name="Form1">
Your name: <input type="text">
</form>
<form id="Form2" name="Form2">
Your car: <input type="text">
</form>
<p>
To access an item in a collection you can either use the number or the name
of the item:
</p>
<script type="text/javascript">
document.write("<p>The first form's name is: " + document.forms[0].name +
"</p>")
document.write("<p>The first form's name is: " +
document.getElementById("Form1").name
+ "</p>")
</script>
</body>
SERVER-SIDE AND CLIENT-SIDE VALIDATION

More Related Content

What's hot (20)

PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
PPSX
Javascript variables and datatypes
Varun C M
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPTX
Java script
Abhishek Kesharwani
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPT
Document Object Model
chomas kandar
 
PDF
Javascript essentials
Bedis ElAchèche
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PDF
Html / CSS Presentation
Shawn Calvert
 
PPT
Java Script ppt
Priya Goyal
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPTX
Css box-model
Webtech Learning
 
PPT
javaScript.ppt
sentayehu
 
PDF
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
PDF
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
PPT
Advanced Cascading Style Sheets
fantasticdigitaltools
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
Javascript variables and datatypes
Varun C M
 
Event In JavaScript
ShahDhruv21
 
Java script
Abhishek Kesharwani
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Document Object Model
chomas kandar
 
Javascript essentials
Bedis ElAchèche
 
jQuery for beginners
Arulmurugan Rajaraman
 
An Introduction to the DOM
Mindy McAdams
 
Html / CSS Presentation
Shawn Calvert
 
Java Script ppt
Priya Goyal
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Document Object Model (DOM)
GOPAL BASAK
 
Css box-model
Webtech Learning
 
javaScript.ppt
sentayehu
 
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Advanced Cascading Style Sheets
fantasticdigitaltools
 

Viewers also liked (9)

PPT
DOM ( Document Object Model )
ITSTB
 
PDF
Javascript and DOM
Brian Moschel
 
PPTX
Document Object Model
Mayur Mudgal
 
PDF
JavaScript and DOM
Jussi Pohjolainen
 
PPTX
Document object model(dom)
rahul kundu
 
PDF
Javascript, DOM, browsers and frameworks basics
Net7
 
PPTX
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
PPTX
Maintainable JavaScript 2012
Nicholas Zakas
 
DOM ( Document Object Model )
ITSTB
 
Javascript and DOM
Brian Moschel
 
Document Object Model
Mayur Mudgal
 
JavaScript and DOM
Jussi Pohjolainen
 
Document object model(dom)
rahul kundu
 
Javascript, DOM, browsers and frameworks basics
Net7
 
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
Maintainable JavaScript 2012
Nicholas Zakas
 
Ad

Similar to Dom(document object model) (20)

PPT
Learn javascript easy steps
prince Loffar
 
PPT
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
 
PDF
Intro to JavaScript
Jussi Pohjolainen
 
PPTX
Javascript 2
pavishkumarsingh
 
PDF
Introducing jQuery
Grzegorz Ziolkowski
 
PDF
Intro to JavaScript
Jussi Pohjolainen
 
PPTX
DHTML - Events & Buttons
Deep Patel
 
PPTX
Unit ii java script and xhtml documents and dynamic documents with javascript
zahid7578
 
PPTX
Web Development Introduction to jQuery
Laurence Svekis ✔
 
PPT
Event Programming JavaScript
MuhammadRehan856177
 
PDF
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
PPTX
DOM Events
Peter Frueh
 
PPT
javascript Event Handling and introduction to event.ppt
Lalith86
 
PPS
CS101- Introduction to Computing- Lecture 32
Bilal Ahmed
 
PDF
jQuery
Ivano Malavolta
 
PPTX
Learning About JavaScript (…and its little buddy, JQuery!)
Julie Meloni
 
PPTX
Javascript
poojanov04
 
PPT
13488117.ppt
SunilChaluvaiah
 
PPT
13488117.ppt
SunilChaluvaiah
 
PPTX
INFT132 093 07 Document Object Model
Michael Rees
 
Learn javascript easy steps
prince Loffar
 
Document_Object_Model_in_javaScript..................................ppt
rahamatmandal2005
 
Intro to JavaScript
Jussi Pohjolainen
 
Javascript 2
pavishkumarsingh
 
Introducing jQuery
Grzegorz Ziolkowski
 
Intro to JavaScript
Jussi Pohjolainen
 
DHTML - Events & Buttons
Deep Patel
 
Unit ii java script and xhtml documents and dynamic documents with javascript
zahid7578
 
Web Development Introduction to jQuery
Laurence Svekis ✔
 
Event Programming JavaScript
MuhammadRehan856177
 
Intro to jQuery @ Startup Institute
Rafael Gonzaque
 
DOM Events
Peter Frueh
 
javascript Event Handling and introduction to event.ppt
Lalith86
 
CS101- Introduction to Computing- Lecture 32
Bilal Ahmed
 
Learning About JavaScript (…and its little buddy, JQuery!)
Julie Meloni
 
Javascript
poojanov04
 
13488117.ppt
SunilChaluvaiah
 
13488117.ppt
SunilChaluvaiah
 
INFT132 093 07 Document Object Model
Michael Rees
 
Ad

More from Partnered Health (20)

PDF
Spam Email identification
Partnered Health
 
PPTX
Final spam-e-mail-detection
Partnered Health
 
PPTX
Java For beginners and CSIT and IT students
Partnered Health
 
PPT
Introduction to computer graphics
Partnered Health
 
PPT
Introduction to computer graphics
Partnered Health
 
PPTX
Hardware concept for graphics
Partnered Health
 
PPTX
Web technology
Partnered Health
 
PPTX
Web inspector for front end developers..
Partnered Health
 
PPTX
Web crawler and applications
Partnered Health
 
PPTX
Semantic markup language
Partnered Health
 
PPTX
Meta tags
Partnered Health
 
PPTX
Listing in web development and uses
Partnered Health
 
PPTX
Fire bugfirebug and ways to install it..
Partnered Health
 
PPTX
Dreamweaver and idm
Partnered Health
 
PPTX
File structure
Partnered Health
 
PPTX
Structure
Partnered Health
 
PPTX
Analysis of unix and windows
Partnered Health
 
PPTX
Organizational aspect of sample survey
Partnered Health
 
PPTX
Question and questionnaire design
Partnered Health
 
PPTX
Sampling
Partnered Health
 
Spam Email identification
Partnered Health
 
Final spam-e-mail-detection
Partnered Health
 
Java For beginners and CSIT and IT students
Partnered Health
 
Introduction to computer graphics
Partnered Health
 
Introduction to computer graphics
Partnered Health
 
Hardware concept for graphics
Partnered Health
 
Web technology
Partnered Health
 
Web inspector for front end developers..
Partnered Health
 
Web crawler and applications
Partnered Health
 
Semantic markup language
Partnered Health
 
Meta tags
Partnered Health
 
Listing in web development and uses
Partnered Health
 
Fire bugfirebug and ways to install it..
Partnered Health
 
Dreamweaver and idm
Partnered Health
 
File structure
Partnered Health
 
Structure
Partnered Health
 
Analysis of unix and windows
Partnered Health
 
Organizational aspect of sample survey
Partnered Health
 
Question and questionnaire design
Partnered Health
 

Recently uploaded (20)

PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PDF
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
PDF
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PDF
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
PDF
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PDF
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PDF
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
PPTX
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PDF
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
Orchestrating things in Angular application
Peter Abraham
 
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 

Dom(document object model)

  • 2. INTRODUCTION • JavaScript arranges objects in a Document Object Model or DOM. • The DOM defines the logical structure of objects and the way an object is accessed and manipulated. • The document object model can be thought of as a hierarchy moving from the most general object to the most specific. • The HTML DOM defines a standard set of objects for HTML, and a standard way to access and manipulate HTML documents
  • 3. • All HTML elements, along with their containing text and attributes, can be accessed through the DOM. • The contents can be modified or deleted, and new elements can be created. • The HTML DOM is platform and language independent
  • 5. HTML DOM OBJECTS • Anchor object • Document object • Event object • Form and Form Input object • Frame, Frameset, and IFrame objects • Image object etc
  • 6. DOM HIERARCHY • The topmost object in the hierarchy is the window object, which contains the other objects in the list, such as the current frame, history list, and the Web page document. • The Web page document contains its own set of objects, including links, anchors, and forms. • Within each form are form objects, such as input boxes, radio buttons, or selection lists.
  • 7. MANAGING EVENTS • An event is a specific occurrence within the Web browser. For example: • opening up a Web page • positioning the mouse pointer over a location on that page • Events are an important part of JavaScript programming, you can write scripts that run in response to the actions of the user, even after the Web page has been opened.
  • 8. ONLOAD & ONUNLOAD <html> <head> <title>Hello/Goodbye page</title> <script type="text/javascript"> function Hello() { globalName=prompt("Welcome to my page. " + "What is your name?",""); } function Goodbye() { alert("So long, " + globalName + ome back real soon."); } </script> </head>
  • 9. <body onload="Hello();" onunload="Goodbye();"> <p>Whatever text appears in the page.</p> </body> </html>
  • 10. USING THE ONCLICK EVENT HANDLER
  • 11. WINDOWS EXAMPLE <html> <head> <title> Fun with Buttons </title> <script type="text/javascript"> function Help(){ var OutputWindow = window.open("", "", "status=0,menubar=0,height=200,width=200"); OutputWindow.document.open();
  • 12. • OutputWindow.document.write("This might be a context-" + • "sensitive help message, depending on the " + • "application and state of the page."); • } • </script> • </head> • <body> • <form id="ButtonForm"> • <p> <input type="button" value="Click for Help" • onclick="Help();" /> </p> • </form> • </body> • </html>
  • 13. EVENTS INITIATED BY THE USER DURING DATA ENTRY
  • 14. GETELEMENTBYID() <html> <head> <script type="text/javascript"> function getElement() { var x=document.getElementById("myHeader"); alert("I am a " + x.tagName + " element"); } </script> </head> <body> <h1 id="myHeader" onclick="getElement()">Click to see what element I am!</h1> </body>
  • 15. GETELEMENTSBYNAME() <html> <head> <script type="text/javascript"> function getElements() { var x=document.getElementsByName("myInput") alert(x.length + " elements!") } </script> </head>
  • 16. <body> <input name="myInput" type="text" size="20"><br /> <input name="myInput" type="text" size="20"><br /> <input name="myInput" type="text" size="20"><br /> <br /> <input type="button" onclick="getElements()" value="How many elements named 'myInput'?"> </body> </html>
  • 17. RETURN THE INNERHTML OF THE FIRST ANCHOR IN A DOCUMENT <html> <body> <a name="first">First anchor</a><br /> <a name="second">Second anchor</a><br /> <a name="third">Third anchor</a><br /> <br /> InnerHTML of the first anchor in this document: <script type="text/javascript"> document.write(document.anchors[0].innerHTML) </script> </body> </html>
  • 18. ACCESS AN ITEM IN A COLLECTION <html> <body> <form id="Form1" name="Form1"> Your name: <input type="text"> </form> <form id="Form2" name="Form2"> Your car: <input type="text"> </form>
  • 19. <p> To access an item in a collection you can either use the number or the name of the item: </p> <script type="text/javascript"> document.write("<p>The first form's name is: " + document.forms[0].name + "</p>") document.write("<p>The first form's name is: " + document.getElementById("Form1").name + "</p>") </script> </body>