INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.

Slides:



Advertisements
Similar presentations
Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
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.
Session 11 Dynamic HTML: Event Model and Filters Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
1 JavaScript Document Object Model & Events. 2 Document Object Model (DOM) JavaScript access to the elements of an HTML document. An object hierarchy.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
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.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 4 Dynamic HTML & CSS.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
EIW: Javascript DOM and Events1 JavaScript Document Object Model & Events.
Web Programming Java Script & jQuery Web Programming.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
DOM (Document Object Model) - Parsing and Reading HTML and XML -
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Document Object Model 1. Document Object Model (DOM) JavaScript access to the elements of an HTML document. An object hierarchy Provides access.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
GetElementById changes outside forms. From form to page  Identified the field by using name  Form.field  Outside a form, use id  Unique on the page.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
CIS 228 The Internet 12/6/11 Forms and Validation.
JQUERY Dr Mohd Soperi Mohd Zahid Semester /16.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
THE DOM.
Week 3: Introduction to Javascript
>> JavaScript: Document Object Model
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
>> Introduction to CSS
Week 4: Introduction to Javascript
CS 371 Web Application Programming
JavaScript.
DHTML Javascript Internet Technology.
>> Dynamic CSS Selectors
DHTML Javascript Internet Technology.
CHAPTER 7 JavaScripts & HTML Documents
© 2015, Mike Murach & Associates, Inc.
JavaScript and the DOM MIS 2402 Jeremy Shafer Department of MIS
Javascript and JQuery SRM DSC.
Events: Changed and Input
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Introduction to Web programming
JavaScript and the DOM MIS 2402 Maxwell Furman Department of MIS
Presentation transcript:

INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE

2 Outline DOM Programming Next class: – Test #2

DOM Programming Interface All HTML elements are objects DOM programming interface: properties and methods of each object. Property: a value that you can get or set (like changing the content of an HTML element) A method is an action you can do (like add or deleting an HTML element) 3

DOM Programming Interface What can DOM do? – Access an element – Change HTML content – Change Attribute value – Change CSS style – Add or Remove an element

Access an Element 1. Most common way: use id of the element. var x = document.getElementById(“hi”); var txt = document.getElementById("hi").innerHTML; 2. Access elements by tag name: var x = document.getElementsByTagName(“p”); var y = element.getElementsByTagName(“p”); 5 Dom1.html Dom_TagName.html

Access an Element 3. By Class Name var x = document.getElementsByClassName(“red”); document.write(x[0].innerHTML); 6 Dom2.html

Access an Element 4. By Object Collections, e.g., forms var x = document.getElementById("frm1"); var txt = ""; for (var i=0;i<x.length;i++) { txt = txt + x.elements[i].value + " "; } 7 Dom3.html

Change HTML Content 1. innerHTML property Useful to get or replace the content of HTML elements. 1) get: var txt1 = document.getElementById(“userName").innerHTML 2) set/ replace document.getElementById("hi").innerHTML = txt; 8 Dom1.html

Change Attribute Value 2. attribute property document.getElementById(id).attribute=new value document.getElementById("image").height = "200"; document.getElementById("image").src="pic2.jpg"; 9 DOM_Attribute.html

Change CSS Style 3. style.property document.getElementById(id).style.property=new style document.getElementById("p2").style.color="blue"; document.getElementById("p2").style.fontFamily="Arial"; document.getElementById("p2").style.fontSize=“20px"; document.getElementById("p2").style.width = "30%"; document.getElementById("p2").style.border = "1px red solid"; 10 DOM_style.html

Add An Element Hello, world! This is my home page. Have Fun function addTextNode() { var desired_element = document.getElementById("main"); var new_element = document.createElement("p"); var new_text_content = document.createTextNode("Have fun!"); new_element.appendChild(new_text_content); desired_element.appendChild(new_element); } 11 addElement.html

Remove An Element function removeNode() { var desired_element = document.getElementById("main"); var remove_element = desired_element.removeChild(desired_element.childNodes[0]); alert(remove_element.innerHTML); } function removeDiv() { var divElem = document.getElementById("main"); divElem.parentNode.removeChild(divElem); } =============================================================== Welcome para 1 para 2 para 3 Remove para 1 Remove Div 12 removeElement.html

DOM Events When a user clicks the mouse (onclick/ondbclick) DOM_event_onclick.html When a web page has loaded (onload/ onunload) DOM_event_onload.html When the mouse moves over an element (onmouseover/ onmouseout/ onmousedown/onmouseup) DOM_event_onmouseover.html DOM_event_onmousedown.html 13

DOM Events When an input field is changed (onchange) DOM_event_onchange.html When a field gets focus (onfocus) DOM_event_onfocus.html 14

DOM Events When a user strokes a key (onkeydown/onkeypress/onkeyup) DOM_event_onkey.html When an HTML form is submitted (onsubmit/onreset) 15

Lab 6 16

Next Class Test 2 17

Thank you!