140 likes | 257 Views
Document Object Model. CSc 2320 Fall 2013. Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools. Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department. In this chapter. Document Access.
E N D
Document Object Model CSc 2320 Fall 2013 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools. Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department
In this chapter • Document Access
The Document Object Model • The DOM(Mapping your html)
The Document Object Model • Each element in html: • A node in DOM tree. • The complete DOM tree
The Document Object Model • How to handle the attributes of a node? • Make them child nodes. • Call attribute nodes.
The Document Object Model • Access the nodes you want • First step: identify the nodes • By Id • In CSS In JavaScript
The Document Object Model • Access the nodes you want • By tag names • In CSS • In JavaScript
The Document Object Model • Access the child nodes from your variable • Access the nodes by class names? • Bummer! There is no native function for that! • No .getElementsByClassName() until you create it!
The Document Object Model • Find parent node • Use attribute “parentNode”; • Find children nodes
The Document Object Model • Find sibling nodes
The Document Object Model • Get attribute • Use “getAttribute()” or attribute name • E.g. • or
The Document Object Model • Set attribute • Use “setAttribute()”.
The Document Object Model • Change style • Use “style” to get CSS rules. • E.g.,
The Document Object Model • JavaScript libraries • Provide different ways to access nodes. • JQuery • By id • By class • Dojo • By id • By class