140 likes | 275 Views
This document serves as a resource for students in the CS 2320 course at GSU, focusing on the Document Object Model (DOM) and its fundamental concepts. It covers key topics such as accessing HTML elements, handling attributes, and navigating the DOM tree. Students will learn how to identify nodes by ID, tag names, and class names, and will explore methods to modify attributes and styles using JavaScript. This edited material draws from "Simple JavaScript" by Kevin Yank and Cameron Adams, along with resources from W3Schools.
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