+ All Categories

Dom

Date post: 08-May-2015
Category:
Upload: soumya
View: 383 times
Download: 5 times
Share this document with a friend
20
Document Object Model
Transcript
Page 1: Dom

Document Object Model

Page 2: Dom

DOM is a platform-and language-neutral interface that will allow

programs and scripts to dynamically access and update the content,

structure and style of documents.

What is DOM?

Page 3: Dom

Why the DOM?

The DOM (Document Object Model) gives you generic

access to most elements, their styles and attributes in a

document.

Page 4: Dom

DOM Architecture

Document object model is a

framework that organizes how

elements are referenced and how

they interact with each other.

Page 5: Dom

Example

How scripts reference elements of a document.

How styles are applied to elements.

How scripts change styles.

Page 6: Dom

Different Document Objects

Document Object

Anchor Object

Button Object

Form Object

Image Object

Event Object

Page 7: Dom

Document Object

Provides access to all HTML elements in a page, from within a script.

Anchor Object

Allows you to create a link to another document.

Button Object

Represents a push button.

Page 8: Dom

Form Object

Used to collect user input, and contain input elements.

Image Object

Represents an embedded image.

Event Object

Performs the action associated with events.

Page 9: Dom

Document object -Example

<html>

<body bgcolor=“#56ce56”>

<script type="text/javascript">

document.write(“GENIUS");

</script>

</body>

</html>

Page 10: Dom

Button object -Example

<html>

<body bgcolor=“#654c45”>

<button id=“Genius1" name=“Genius1">ClickMe!</button>

<p>The name of the button is:

<script type="text/javascript">

document.write(document.getElementById(“Genius1").name);

</script></p>

</body>

</html>

Page 11: Dom

Form object -Example

<html><body bgcolor="#87cb56">

<form id="frm1" action="form_action.asp">

Last name: <input type="text" name="lname" value="Adi" /><br />

<input type="submit" value="Submit" />

</form>

<p>Return the value of each element in the form:</p>

<script type="text/javascript">

var x=document.getElementById("frm1");

for (var i=0;i<x.length;i++)

{

document.write(x.elements[i].value);

document.write("<br />");

} </script></body></html>

Page 12: Dom

JavaScript HTML DOM

<html><head>

<script type="text/javascript">

function disable_button()

{

document.getElementById("myButton").disabled=true;

}

</script></head>

JavaScript is used to access and manipulate HTML DOM objects.

Example

Page 13: Dom

<body>

<button id="myButton" type="button" onclick="disable_button()">

Click to disable me</button>

</body>

</html>

Example Cont…

Page 14: Dom

XML -DOM

XML DOM defines a standard way for accessing and

manipulating XML documents.

OR

The XML DOM is a standard for how to get, change, add, or

delete XML elements.

Page 15: Dom

<?xml version="1.0"?>

<bookstore>

<book category=“web">

<title lang="en">Harry</title>

<author>Aditya</author>

<year>2010</year>

<price>2000</price>

</book>

</bookstore>

XML File

Page 16: Dom

<html><head>

<script type="text/javascript" src="loadxmldoc.js">

</script></head>

<body>

<script type="text/javascript">

xmlDoc=loadXMLDoc("books.xml");

document.write(xmlDoc.documentElement.nodeName);

</script></body>

</html>

Loading of XML file using JavaScript

Page 17: Dom

Advantages of DOM

Language and Implementation-Neutral Interface.

Important feature of the DOM is to provide a standard

programming interface that can be used in a wide variety of

environments and applications.

Interoperability.

Benefit of having a standard API is interoperability which is a

necessity for documents sent over the Internet.

Page 18: Dom

HTML and XML Support.

DOM is designed with both HTML JavaScript and XML in mind.

Style Sheets Support.

DOM specifies a way to manipulate and change CSS and XSL style

sheets.

Advantages of DOM (Cont…)

Page 19: Dom

Disadvantages

Stores the entire document in memory.

DOM was written for any language, method naming conventions

don’t fallow standard java programming conventions.

Page 20: Dom

Thank You


Recommended