Lect 14 JavaScript DOM
Lect 14 JavaScript DOM
JavaScript DOM
Prompt box
User input
confirmation
Not confirmed
2. Document Object Model (DOM)
• Once html element are rendered (painted) in
the browser window, browser can not
recognize them
• To create interactive web pages it is vital that
the browser continues to recognize HTML
elements
• JavaScript enabled browsers do this because
they recognize and uses DOM
Window
Textboxes
select list
of forms
element
buttons
Array of
Reset
li
files
• document.forms[0].elements[0].value
• document.images[0].src
• document.links[0].href
2.1 Retrieving HTML elements
• The getElementById() method is a workhorse
method of the DOM
• It retrieves a specified element of the HTML
document and returns a reference to it
• To retrieve an element, it must have an
unique id
– document.getElementById(“element-id”)
Function starts
Getting
reference to pic
Accessing
Attributes
Setting id
Image tag
Calling function
Mubashir Ali - Lecturer (Department of
18
Computer Science)
2.2 Retrieving the text of an element
Getting reference to
element
Getting text
Paragraph text
Getting reference to
element
Changing the
value of attribute