DOCUMENT OBJECT MODEL
A web page is a document
which can be either displayed in the browser window or as the HTML source. When
a web page is loaded, the browser creates a Document Object Model
of the page and this can be modified with the scripting language like
JavaScript. The DOM standard is separated into 3 different parts:
- Core DOM - standard model for all document
types
- XML DOM - standard model for XML documents
- HTML DOM - standard model for HTML documents
TREE STRUCTURE
The DOM consists of a tree
structure of nested nodes, which is often called as the DOM tree. Like an ancestral
family tree, which consists of parents, children, and siblings. The nodes in
the DOM are also referred as parents,
children, and siblings, depending on their relation to other nodes. DOM is a
way to represent the webpage in the structured hierarchical way so that it will
become easier for programmers and users to glide through the document. With
DOM, we can easily access and manipulate tags, IDs, classes, Attributes or
Elements using commands or methods provided by Document object.Mainly tree structure makes the search process in a faster way.
The html element
node is the parent node. head and body elements are siblings, children
of html.
OBJECT MODEL
Documents
are modelled using objects, and the model includes not only the structure of a
document but also the behaviour of a document and the objects of which it is
composed of like tag elements with attributes in HTML.Generally object Model use in-memory method that means it store data in RAM and process the data.
ADVANTAGES OF DOM
By manipulating the DOM, you have infinite
possibilities. You can create applications that update the data of the page
without needing a refresh. Also, you can create applications that are
customizable by the user and then change the layout of the page without a
refresh. You can drag, move, and delete elements.
MOSTLY USED DOM METHODS
getElementById()
This method returns the element that contains the name id passed.
As we know, id’s should be unique, so it’s a very helpful method to
get only the element you want.
getElementsByClassName()
This method returns an HTMLCollection of all those elements
containing the specific name class passed.
getElementsByTagName()
This works the same way as those methods above: it also returns an HTMLCollection,
but this time with a single difference: it returns all those elements
with the tag name passed.
Comments
Post a Comment