SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Making web pages interactive with JavaScript.

Slides:



Advertisements
Similar presentations
MA foundation Creating webpages using XHTML (part 1) Simon Mahony CCH
Advertisements

Intro to HTML. HTML HTML = HyperText Markup Language Used to define the content of a webpage HTML is made up of tags and attributes Content.
Teppo Räisänen LIIKE/OAMK 2010
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
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.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
SE-2840 Dr. Mark L. Hornick 1 HTML input elements and forms.
16 HTML Tables and Frames Section 16.1 Create a basic table using HTML Define borders Merge cells Align content in tables Section 16.2 Create a frames-based.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Basics of HTML.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
JS: Document Object Model (DOM)
CSS Positioning Creating Special Effects with CSS CS202 Working with Cascading Style Sheets (Chapter 4) CS202 1.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
SE-2840 Dr. Mark L. Hornick 1 Separating Structure from Presentation: CSS.
INTRODUCTION TO HTML5 Styling Text. Change the Font Size  You can use the font-size property to change the font size for a document’s text.  Instead.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
Title, meta, link, script.  The title looks like:  The tag defines the title of the document in the browser toolbar.  It also: ◦ Provides a title for.
1 CSC 121 Computers and Scientific Thinking David Reed Creighton University HTML and Web Pages.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
CSS: Cascading Style Sheets. 2 What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
WRT235: Writing in Electronic Environments Basic CSS.
 cascade Style Sheets (CSS) is a mark-up language that was first proposed in 1994 by Håkon Wium Lie. CSS works in conjunction with HTML to greatly increase.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
HTML Basic IST2101. Keep In Mind Programming can be time consuming. Plan ahead!
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Advanced Web Development Instructor: Thomas Bombach.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
Host Objects: Browsers and the DOM
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
CHAPTER TWO HTML TAGS. 1.Basic HTML Tags 1.1 HTML: Hypertext Markup Language  HTML stands for Hypertext Markup Language.  It is the markup language.
Advanced CSS. Display  Hiding an element can be done in two ways  display:none  Element is hidden and will no longer take up space on the page  Can.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
IN THIS LESSON, WE WILL BECOME FAMILIAR WITH HTML AND BEGIN CREATING A WEB PAGE IN YOUR COMPUTER HTML – the foundation.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
1 Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size, font color etc…
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
DHTML.
Web Basics: HTML/CSS/JavaScript What are they?
Programming Web Pages with JavaScript
Webpage layout using CSS
Intro to CSS CS 1150 Fall 2016.
Document Object Model (DOM): Objects and Collections
Cascading Style Sheets - Building a stylesheet
Intro to CSS CS 1150 Spring 2017.
The Document Object Model
Introduction to Programming the WWW I
Web Design and Development
Making web pages interactive with JavaScript
Cascading Style Sheets - Building a stylesheet
Presentation transcript:

SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Making web pages interactive with JavaScript

Recall: window is the top-level object in the BOM hierarchy SE-2840 Dr. Mark L. Hornick 2 Note: The Document Object Model (DOM) is a child/subset of the BOM

SE-2840 Dr. Mark L. Hornick 3 All nodes have relationships to each other Every node has a parent except for the document node Most elements have descendant nodes p em Here is anword emphasized id=“em1” id=“par1” Element node Text node Attribute node document html title body Demo head

SE-2840 Dr. Mark L. Hornick 4 The DOM implemented by modern web browsers allows you to change virtually anything on a webpage p em Element Here is anTextword emphasized Attribute id=“em1” id=“par1” Here is an emphasized word Every element of a webpage can be accessed as a DOM object

SE-2840 Dr. Mark L. Hornick 5 Some document methods and attributes for accessing various subnodes document Methods: getElementById(id) – gets the Element in the document with a specified id getElementsByTagName(tagName) – gets a collection of Elements with the specified tag name (e.g. “h1”) getElementsByClassName(className) – gets a collection of Elements with the specified class name (e.g. “highlights”) getElementByName() – gets a collection of Elements with the specified name (ex of named element: ) querySelectorAll() – gets a collection of Elements with the specified selector pattern (e.g. “p em”) querySelector() – gets the first Element with the specified selector pattern (e.g. “p em”) 2013 Note: Seems to be limited support for this method (fails on FF) document Properties anchors[ ], forms[ ], images[ ], links[ ] – collections of all objects of this type within the current document body – the Element object documentElement– the Element object Note: The document object contains many other methods and properties for various other purposes – view them from within the browser debugger

SE-2840 Dr. Mark L. Hornick 6 JavaScript access to DOM nodes var pars = document.getElementsByTagName(“p”);//array of all nodes var e = pars.item(0); // first e = pars[0]; // also first e = document.getElementById(“em1”);// specific element with #em1 id p em Here is anword emphasized id=“em1” id=“par1” Element node Text node Attribute node

SE-2840 Dr. Mark L. Hornick 7 Navigating among nodes var p1 = document.getElementById(“par1”); // node with id=“par1” var first = p1.firstChild; // first child node: “Here is an” var next = first.nextSibling; // next child: “em” var last = p1.lastChild; // last child: “word” var prev = last.prevSibling; // previous child: “em” var parent = p1.parentNode; // whatever element contained p em Here is anword emphasized id=“em1” id=“par1” Element node Text node Attribute node

SE-2840 Dr. Mark L. Hornick 8 Getting the HTML within a node var p1 = document.getElementById(“par1”); // node with id=“par1” var markup = p1.innerHTML; // “Here is an emphasized word” p em Here is anword emphasized id=“em1” id=“par1” Element node Text node Attribute node

SE-2840 Dr. Mark L. Hornick 9 Besides changing the existing HTML markup within a node, we can script the DOM to create entirely new nodes var elm = document.createElement("p"); // creates free-standing var txt = document.createTextNode("Hello"); elm.appendChild(txt); elm.setAttribute("id", “par1"); txt = document.createTextNode(" there."); elm.appendChild(txt); document.body.appendChild(elm); // put in p Hello there. id=“par1” body Hello there.

SE-2840 Dr. Mark L. Hornick 10 The id or class of an existing element can be changed dynamically in order to modify the element’s appearance var elm = document.getElementById(“par1”); elm.setAttribute("id", “par2"); p Hello there. id=“par1” body Hello there. Hello there. id=“par2” #par1{ color:blue;} #par2{ color:red;} …

All modern browsers implement the element’s style object The style object contains the element’s CSS properties You can use the style object to change any CSS property the element supports Style property names generally correspond to CSS property names, with a few exceptions In the case of CSS property names that contain a hyphen, remove the hyphen and capitalize the next letter for the corresponding style property CSS property: “background-color” Style object property: “backgroundColor” SE-2840 Dr. Mark L. Hornick 11

SE-2840 Dr. Mark L. Hornick 12 Or style attributes can be modified directly via the style object p Hello there. id=“par1” body The element’s id remains “par1”, but the style object is more specific than the CSS rule, so the CSS rule is overridden. #par1{ color:blue;} #par2 { color:red;} … var elm = document.getElementById(“par1”); elm.style.color=“green”; …

SE-2840 Dr. Mark L. Hornick 13 The visibility and display style attributes affect whether the element is seen or not, but in different ways var elm = document.getElementById(“error”);// gets error message elm.style.display = “none”;// removes element from display process elm.style.display = “block”;// includes element elm.style.visibility = “hidden”; // hides elm.style.visibility = “visible”; // shows The display attribute, when set to “none”, causes the element to be removed from the display. Other elements will fill in the space left behind. The visibility attribute, when set to “hidden”, causes the element to be kept in the display, but not shown. An empty space will appear where the element would otherwise appear. This is a common approach to displaying or hiding web page error messages