CHAPTER 11 USING THE DOCUMENT OBJECT MODEL. LEARNING OBJECTIVES How by using events such as mouseover or mouseout, your pages can respond to specific.

Slides:



Advertisements
Similar presentations
Microsoft Expression Web-Illustrated Unit K: Working with Behaviors.
Advertisements

HTML I. HTML Hypertext mark-up language. Uses tags to identify elements of a page so that a browser such as Internet explorer can render the page on a.
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
The Web Warrior Guide to Web Design Technologies
1 Lesson 10 Using JavaScript with Styles HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML
COMPSCI 345 / SOFTENG 350 TUTORIAL WEEK 8 | SAM KAVANAGH.
HTML and Web Page Design Presented by Frank H. Osborne, Ph. D. © 2005 ID 2950 Technology and the Young Child.
Tutorial 16 Working with Dynamic Content and Styles.
Computer Science 1611 Internet & Web Creating Webpages Hypertext and the HTML Markup Language.
Web Page Development Identify elements of a Web Page Start Notepad
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
 2008 Pearson Education, Inc. All rights reserved. 1 Introduction to HTML.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
CHAPTER 31 BROWSER IDENTIFICATION. LEARNING OBJECTIVES What a “hack” is and why Web developers try to avoid them How to determine a browser’s user-agent.
HTML Overview Part 2 – Paragraphs, Headings, and Lines 1.
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
Introduction to JavaScript Dr. John P. Abraham University of Texas – Pan American.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
Links in HTML. Hyperlinks or links Millions of linked web pages make up the World Wide Web Used to connect a web page to another web page on the same.
CS 299 – Web Programming and Design Introduction to HTML.
Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Chapter 2 Developing a Web Page. A web page is composed of two distinct sections: –The head content –The body Creating Head Content and Setting Page Properties.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
History, Navigator, Screen and Form Objects Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
1 Goals and Objectives Goals Goals Understand how JavaScript makes it possible to interact with web pages, minimizes client/server traffic, enables verification.
Intro to Dreamweaver Web Design Section 7-1 Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development I” Course.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
HTML IMAGES. CONTENTS IMG Tag Alt Attribute Setting Width and Height Of An Image Summary Exercise.
Are You Smarter Than a 5 th Grader? 1,000,000 5th Grade HTML 5th Grade Syntax 4th Grade HTML 4th Grade Syntax 3rd Grade HTML 3rd Grade Syntax 2nd Grade.
HTML Links HTML uses a hyperlink to another document on the Web.
Headings are defined with the to tags. defines the largest heading. defines the smallest heading. Note: Browsers automatically add an empty line before.
Basic HTML.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Tutorial #1 Using HTML to Create Web Pages. HTML, XHTML, and CSS HTML – HyperText Markup Language The tags the browser uses to define the content of the.
Adding Interactivity Comp 140 Fall Web 2.0 Major change in internet usage –From mostly static pages Text Graphics Simple links –To new paradigm.
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.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
Project 02 Creating and Editing a Web Page Concept Map of Unit Creating and Editing a Web Page Key Learning Understand the elements to create a web page.
1 Introduction to HTML. 2 Definitions  W W W – World Wide Web.  HTML – HyperText Markup Language – The Language of Web Pages on the World Wide Web.
Basic HTML Page 1. First Open Windows Notepad to type your HTML code 2.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML.
Module 1 Introduction to JavaScript
Web Basics: HTML/CSS/JavaScript What are they?
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Development & Design Foundations with HTML5 7th Edition
AN INTRODUCTORY LESSON TO MAKING A SIMPLE WEB PAGE By: RC Emily Solis
CT Web Development, Colorado State University
Introduction to HTML.
JavaScript.
Web Programming and Design
Web Programming and Design
Web Programming and Design
Presentation transcript:

CHAPTER 11 USING THE DOCUMENT OBJECT MODEL

LEARNING OBJECTIVES How by using events such as mouseover or mouseout, your pages can respond to specific user mouse operations How using an object’s innerHTML attribute allows you to access the nested HTML tags because many HTML tags enclose other HTML tags How using the Window object allows you to use JavaScript code within your page to access specifics about the current window, such as its size or relative screen position How using the Navigator object allows you to use JavaScript code to determine the Web browser that is displaying the page contents How using the Screen object allows you to use JavaScript code within your page to determine specifics about the current screen resolution How using the Location object allows you to use JavaScript code within your page to determine specifics about the current web-page, such as its URL, file path, or query string

DOM OVERVIEW AT:

UNDERSTANDING OBJECTS An object, in the simplest sense, is a “thing.” With respect to an HTML page, an object might be a paragraph, image, or table. All things have attributes, and the same is true for DOM objects. A paragraph, for example, has related text; an image has a corresponding source URL; and a table might have a height and a width. In addition to attributes, the browser associates different events with objects, such as a mouse entering a table, hovering over an image, and so on. The sections that follow use different JavaScript functions to leverage object attributes and in the process change a webpage’s behavior.

USING DOM TO CHANGE AN IMAGE function imageDog() { var ImageObject = document.getElementById("DogCat"); ImageObject.src = " } function imageCat() { var ImageObject = document.getElementById("DogCat"); ImageObject.src = " }

USING DOM TO CHANGE TEXT COLORS function greenText() { var paragraphObject = document.getElementById("Paragraph"); paragraphObject.style.color = 'yellow'; } function blueText() { var paragraphObject = document.getElementById("Paragraph"); paragraphObject.style.color = 'blue'; } Paragraph text

DETECTING A WINDOW-RESIZE EVENT

ACCESSING AN ELEMENT’S INNERHTML Paragraph one Paragraph two Paragraph three Show innerHTML

CHANGING AN ELEMENT’S INNERHTML function toHindi() { var paragraphObject = document.getElementById("Paragraph"); paragraphObject.innerHTML = " गर्भावस्थाक आमतौर पर 9 महीयने (40 सप्ताैह ) तक चलती है, जिसे आपकी पिछली माहवारी की तारीख से गिना जाता है। अपनी सटीक नियत तिथि का अनुमान लगाने के लिए ( लगभग 2 सप्ताकह तक सटीक ) अपनी पिछली माहवारी की तारीख से आरंभ करें और उसमें 280 दिन "; } function toEnglish() { var paragraphObject = document.getElementById("Paragraph"); paragraphObject.innerHTML = "Pregnancy normally lasts 9 months (40 weeks), calculated from the date of your last menstrual period. To estimate (accurate to about 2 weeks) your due date, start with the date of your last menstrual cycle and then add 280 days."; } Pregnancy normally lasts 9 months (40 weeks), calculated from the date of your last menstrual period. To estimate (accurate to about 2 weeks) your due date, start with the date of your last menstrual cycle and then add 280 days.

WRITING CONTENT TO THE CURRENT DOCUMENT document.writeln("Hello, DOM"); Other document content

WRITING HTML TO THE CURRENT DOCUMENT document.writeln(" Hello, DOM"); Other document content

DISPLAYING WINDOW SPECIFICS alert("Top: " + window.screenY + " Window.left: " + window.screenX + " Inner Height: " + window.innerHeight + " Inner Width: " + window.innerWidth);

PRINTING THE CURRENT WINDOW’S CONTENTS Print Window

DISPLAYING SCREEN SPECIFICS alert("Width: " + screen.width + " Height: " + screen.height + " Colors: " + screen.colorDepth);

DISPLAYING THE CURRENT BROWSER NAME alert(navigator.appName);

USING THE HISTORY OBJECT function changeContent() { var value = document.getElementById('PullDown').value; history.go(value); } for (i = 0; i " + i + " "); }

DISPLAYING CURRENT PAGE INFORMATION alert("Host name: " + location.host + " Path: " + location.pathname + " Protocol: " + location.protocol);

REAL WORLD: W3SCHOOLS

SUMMARY To render a webpage, a browser treats the elements that make up the page, such as paragraphs, headings, images, lists, tables, and so, as objects. In the simplest sense, an object is a thing consisting of attributes, events, and operations. One object may be a paragraph, one an image, one a table, and so on. To access such objects within a webpage, browsers use the Document Object Model, or DOM. This chapter introduced the Document Object Model. Using JavaScript within your webpage, you can use DOM to access individual page components to create dynamic page content that your page can change based on operations the user performs. You can also use DOM objects to perform key operations, such as validating a form’s contents.