Client Side Technologies: Document Object Model (DOM)
Client Side Technologies: Document Object Model (DOM)
W3C standard.
Platform independent.
Language independent
DOM Model
window
Properties:
Property Description
Methods:
Method Description
write() Writes one or more HTML expressions to a
document in the specified window.
writeln() Writes one or more HTML expressions to a
document in the specified window and follows them
with a new line character.
Document(Cont.)
Methods:
o for accessing document elements.
Method Description
getElementById("ID") For accessing any element on the
page via its ID attribute
getElementsByName(“NAME”) Returns a collection of objects with
the specified name
Methods:
o for accessing document elements.
Method Description
document.querySelector(css rule) Returns the first element that matches a
specified CSS selector(s) in the document.
document.querySelectorAll(css rule) Returns a NodeList containing all elements
that matches a specified CSS selector(s) in
the document.
Document(Cont.)
Document(Cont.)
Collections :
Collection Description
Event Handler:
onClick
onDblClick
onKeyDown
onKeyPress
onKeyUp
onMouseDown
onMouseUp
Image
Properties:
Event handlers
onmouseout onmouseover onmousemove onclick ondblclick
Form
HTML:
<FORM>
Properties [NAME="formName"]
[TARGET="frameName or windowName"]
[onSubmit="handlerText Or Function"] Events
[onReset="handlerText Or Function"]>
</FORM>
Form(Cont.)
Properties:
Property Description
Methods :
Method Description
reset() Resets the form.
Clicking the reset button clears all contents that
the user has made.
submit() Submits a form.
Clicking the submit button submits the content
of the form to the server
Form(Cont.)
Event handlers:
Event Description
form
HTML:
<input type="text"
id="id"
value="string"
maxlength="n"
size=“x"
/>
Text (Cont.)
Properties:
properties Description
value Sets or returns the value of the value attribute
of a text field.
Methods
Method Description
blur() Removes focus from the field.
Event Handlers:
Event Handler Description
onfocus The field gains focus when the user tabs into or clicks
inside the control.
onblur The field loses focus when the user tabs from or
clicks outside the control.
Onchange The field loses focus after the contents of the control
have changed.
Drop down list
HTML:
https://www.w3schools.com/jsref/dom_obj_select.asp
https://www.w3schools.com/jsref/coll_select_options.asp
Drop down list(Cont.)
Properties for Option:
Property Description
A true or false value indicating whether an option is
selected
chosen.
value The value associated with an option.
text The text label associated with an option.
Sets or returns the index position of an option in a drop-
index
down list
Drop Down(Cont.)
Methods
Method Description
add() Adds an option to a dropdown list
Event Handlers:
HTML:
<input type="radio"
id="id"
name="name"
value="string"
checked
/>
Radio button(Cont.)
Properties
Properties Description
Method Description
blur() Removes focus from the field.
Event Handlers:
HTML:
<input type="checkbox"
id="id"
name="name"
value="string"
checked
/>
Check Box(Cont.)
Properties:
Property Description
Method Description
blur() Removes focus from the field.
Event Handlers:
HTML:
<input type="button“
id="id“
value="string"
/>
Button(Cont.)
Methods:
Method Description
blur() Removes focus from the field.
Properties:
properties Description
value Sets or returns the text that is displayed on the
button
Event Handlers:
Event Handler Event
The mouse is clicked and released with the
onclick
cursor positioned over the button.
The mouse is double-clicked with the
ondblclick
cursor positioned over the button.
The mouse is pressed down with the cursor
onmousedown
positioned over the button.
onmouseout The mouse cursor is moved off the button.
The mouse cursor is moved on top of the
onmouseover
button.
The mouse button is released with the
onmouseup
cursor positioned over the button.
DOM HTML objects reference
HTML:
<span id=“s1”>
Hello There!
</ span>
<div id=“d1”>
Hello There!
</div>
Introducing SPAN & DIV (Cont.)
Properties (work with content elements):
properties Description
innerText Sets or returns the text that the control contains.
“innerText is aware of the rendered appearance of text,
while textContent is not.”
https://developer.mozilla.org/en-
US/docs/Web/API/HTMLElement/innerText
textContent Sets or returns the text that the control contains,
and execute the HTML tags in the text.
Differences from innerText:
https://developer.mozilla.org/en-
US/docs/Web/API/Node/textContent
innerHTML Sets or returns the HTML text code that the
control contains, and execute the HTML tags in
the text.
Introducing SPAN & DIV (Cont.)
Properties:
<script>
document.getElementById(“d1”).innerText =“<b>new text</b>”;
///<b>new text</b>
document.getElementById(“d1”).textContent=“<b>new text</b>”;
//<b>new text</b>
document.getElementById(“d1”).innerHTML=“<b>new text</b>”;
//new text
</script>
Variety of DOM References
function myFunction(myObject)
{
myObject.value = ”In the function!!“
}
<script>document.writeln(“Thank
You!”)</script>