uk
CSC1014
DOM: Principles
DOM = Document Object Model
Language/platform neutral interface to a document Defines document objects, the relationships between them & their methods and properties
XHTML DOM describes XHTML documents and the browser window that contains them Allows access to any part of a document
As predefined (by standard/browser) objects Via location in hierarchical document tree As author-defined objects (using id attributes)
JISC Netskills
CSC1014
location
status
document
history
frames
images
forms
links
document
button
JISC Netskills
checkbox
select
text
CSC1014
Most standardised as W3C DOM 1.0 but... ....(Historically) browsers developed different DOM(s)
Netscape (Layers) old so completely ignore Internet Explorer (All) much less important now (but useful to test for) W3C (ID) DOM standard in use in most browsers
JISC Netskills
CSC1014
DOM-defined object
User-defined objects
Problems
Property
You need to know the hierarchy! Uses the deprecated name attribute in elements other than form controls and links (Cannot be used in strict HTML) Not applicable to all page elements
JISC Netskills
CSC1014
<form method="get" action=""> <input type="text" name="input1" /> <input type="text" name="input2" /> <input type="text" name="input3" /> </form>
CSC1014
CSC1014
JISC Netskills
CSC1014
if (document.all) { domALL = "OK"; //Prob some version of IE } if (document.getElementById) { domW3C = "OK"; //Prob support for W3C DOM }
JISC Netskills
CSC1014
...and possibly...
Collections (of sub objects) (e.g. the <option> list for a <select> object) Methods (invoked or handled when they occur)
Uses dot operator (.) to access objects Range of ways to start the process
JISC Netskills
CSC1014
Read/Set properties
CSC1014
http://www.w3schools.com/jsref/
All the HTMLElement objects in the page support a set of basic properties, methods & collections e.g.
Description Returns an array of attributes held by current tag Returns an array of the children of the current tag Description Returns the tag name (in UPPER case e.g. H1) Returns the object type Set (or return) the HTML contents of a tag Description Gives focus to the element (e.g. a form field) "Click" the element (e.g. a link or button) Create a new attribute for the element
Properties
tagName nodeType innerHTML
Methods
focus() click() setAttribute()
JISC Netskills