1 The Information School of the University of Washington Nov 1fit100-16-dom © 2006 University of Washington Document Object Model (DOM) INFO/CSE 100, Fall.

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

Introduction to HTML & CSS
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Document Object Model (DOM) JavaScript manipulation of the DOM.
1 The Information School of the University of Washington Oct 30fit review Programming Review INFO/CSE 100, Fall 2006 Fluency in Information Technology.
1 The Information School of the University of Washington Nov 8fit review © 2006 University of Washington Midterm 2 Review INFO/CSE 100, Fall 2006.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
Oct 25 1 The Information School of the University of Washington fit control © 2006 University of Washington Control Flow INFO/CSE 100, Fall 2006.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
4.1 JavaScript Introduction
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
1 Week Three: Using Scripts and Forms in HTML (Week Three) By Dr Fadi Safieddine.
Adminisztratív November 24.-én az előadás és a gyakorlat elmarad A nagy gyakorlati feladatok beszedése a december 1.-én tartandó gyakorlatra tolódik A.
CS 299 – Web Programming and Design Introduction to HTML.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
Unobtrusive JavaScript
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
CITS1231 Web Technologies JavaScript and Document Object Model.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
USING XML AS A DATA SOURCE. Data binding is a process by which information in a data source is stored as an object in computer memory. In this presentation,
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
1 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Document Object Model (DOM)
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Object Model. Biggest Advantage of JavaScript  I can access values of HTML elements using JavaScript  I can modify values of HTML elements.
Creating Your 1 st Web Page. Tags Refers to anything between on a webpage Most appear in pairs surrounding content Some appear as empty tags (no closing.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
XML DOM Week 11 Web site:
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Net-centric Computing Document Object Model (DOM).
Introduction to Web Site Development Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript.
1 The Document Object Model. 2 Objectives You will be able to: Describe the structure of the W3C Document Object Model, or DOM. Use JavaScript to access.
Programming Web Pages with JavaScript
Document Object Model (DOM)
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Internet of the Past.
Section 17.1 Section 17.2 Add an audio file using HTML
Document Object Model (DOM)
Document Object Model (DOM)
Week 11 Web site: XML DOM Week 11 Web site:
Document Object Model (DOM)
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Document Object Model (DOM)
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Document Object Model (DOM): Objects and Collections
Introduction to HTML5.
Teaching slides Chapter 6.
INFO/CSE 100, Spring 2005 Fluency in Information Technology
The Most Basic HTML Page
Web Programming and Design
Presentation transcript:

1 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Document Object Model (DOM) INFO/CSE 100, Fall 2006 Fluency in Information Technology

2 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington References »JavaScript, The Definitive Guide by David Flanagan. Publisher O'Reilly »W3C Document Object Model »Document Object Model in Mozilla

3 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington What the heck is the DOM? Document Object Model »Your web browser builds a model of the web page (the document) that includes all the objects in the page (tags, text, etc) »All of the properties, methods, and events available to the web developer for manipulating and creating web pages are organized into objects »Those objects are accessible via scripting languages in modern web browsers

Sample DOM Document An HTML Document This is a simple document. This is what the browser reads This is what the browser displays on screen.

Document "Sample DOM Document" "An HTML Document" "This is a" "simple" "document" This is a drawing of the model that the browser is working with for the page.

6 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Why is this useful? Because we can access the model too! »the model is made available to scripts running in the browser, not just the browser itself A script can find things out about the state of the page A script can change things in response to events, including user requests »We have already used this capability in the GUI programming that we've done

7 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Recall our simple GUI example This GUI has several simple controls. Two buttons to control the results One text field to display the results One pair of radio buttons to control the display One button to reinitialize

8 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington setResults(resultString) the highlighted script above makes reference to several objects in the document object model function setResults(resultString) { var tempString = resultString; if (document.getElementById("radioLC").checked) { tempString = tempString.toLowerCase(); } else if (document.getElementById("radioUC").checked) { tempString = tempString.toUpperCase(); } document.getElementById("resultField").value = tempString; }

9 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington document.getElementById("radioLC").checked Reference to several nodes in the model of the page that the browser constructed document »The root of the tree is an object of type HTMLDocument »Using the global variable document, we can access all the nodes in the tree, as well as useful functions and other global information title, referrer, domain, URL, body, images, links, forms,... open, write, close, getElementById,...

Some information from a document DOM Sample 1 Information about this document. document.write(" Title: ",document.title); document.write(" Referrer: ",document.referrer); document.write(" Domain: ",document.domain); document.write(" URL: ",document.URL);

11 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington document.getElementById("radioLC").checked getElementById("radioLC") »This is a predefined function that makes use of the id that can be defined for any element in the page »An id must be unique in the page, so only one element is ever returned by this function »The argument to getElementById specifies which element is being requested

Some information about elements DOM Sample B function showInfo() { var element = document.getElementById("opener"); var buffer = element.id + " tag is " + element.tagName; alert(buffer); element = document.getElementById("actionItem"); buffer = element.id + " tag is " + element.tagName; buffer += ", type is "+element.type; alert(buffer); } The id attribute is very helpful. This is the closing paragraph. Show Info

14 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington document.getElementById("radioLC").checked checked »This is a particular property of the node we are looking at, in this case, a radio button »Each type of node has its own set of properties for radio button: checked, name,... refer to the HTML DOM for specifics for each element type »Some properties can be both read and set

Some specific properties Simple Sample GUI function setResults(resultString) { var tempString = resultString; if (document.getElementById("radioLC").checked) { tempString = tempString.toLowerCase(); } else if (document.getElementById("radioUC").checked) { tempString = tempString.toUpperCase(); } document.getElementById("resultField").value = tempString; }

17 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Getting vs. Setting var oldvalue = document.getElementById("resultField").value; document.getElementById("resultField").value = "new value";

18 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Just the tip of the DOM The HTML Document Object Model is a standard for structuring data on a web page »The field is advancing rapidly as people recognize the benefits of standardized structure and access »The DOM is steadily improving to cover general purpose data structuring requirements XML (Extendible Markup Language) also uses the Core DOM to specify its structured data »similar to HTML but more carefully defined

DOM Sample 3 var switchCount = 0; var adjectives = ["simple","complex","fascinating","unique"]; function switcher() { if (switchCount == (adjectives.length - 1)) switchCount = 0; else switchCount++; var italicNode = document.getElementById("adjPhrase"); italicNode.firstChild.nodeValue = adjectives[switchCount]; } An HTML Document This is a simple document. switch This is what the browser reads (dom3.html).

This is what the browser displays on screen.

21 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington What will be displayed on screen? Form groups of 5 or 6 Work together to answer the question: What will be written to the screen. TIP: The code runs fine - there are no errors or other “tricks”