School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.

Slides:



Advertisements
Similar presentations
The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
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.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
CS134 Web Design & Development Attributes, Lists, Tables, Links, and Images Mehmud Abliz.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
CST JavaScript Validating Form Data with JavaScript.
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.
JS: Document Object Model (DOM)
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
DOM and JavaScript Aryo Pinandito.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
HTML Overview Part 4 – Tables 1. HTML Tables  Tables are defined with the tag pair.  A table is divided into rows with tag pairs. o tr stands for "table.
Integrating JavaScript and HTML5 HTML5 & CSS 7 th Edition.
CITS1231 Web Technologies JavaScript and Document Object Model.
Manipulating the DOM CST 200 – JavaScript 3 –
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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 Concepts and Techniques Fourth Edition Project 12 Creating and Using XML Documents.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
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.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
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.
 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.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
Rich Internet Applications 3. Client JavaScript. Document Object Model (DOM) The DOM, is an interface that allows scripts or programs to access and manipulate.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
HTML CS 105. Page Structure HTML elements control the details of how a page gets displayed. Every HTML document has the following basic structure: … …
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
XML DOM Week 11 Web site:
DOM Dr. Reda Salama. Back to the HTML DOM Once we get a response back from the server, we probably want to update our HTML page The HTML page itself is.
HTML Help book. HTML HTML is the programming language used to make web pages for the Internet. HTML stands for Hyper Text Markup Language. HTML is made.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
THE DOM.
Introduction to.
>> JavaScript: Document Object Model
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
CGS 3066: Web Programming and Design Spring 2017
Applied Online Programming
CS 371 Web Application Programming
CGS 3066: Web Programming and Design Spring 2016
Intro to JavaScript CS 1150 Spring 2017.
Working with Dynamic Content and Styles
© 2015, Mike Murach & Associates, Inc.
LING 408/508: Computational Techniques for Linguists
Chengyu Sun California State University, Los Angeles
JavaScript and the DOM MIS 2402 Maxwell Furman Department of MIS
Presentation transcript:

School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within

School of Computing and Information Systems CS 371 Web Application Programming JavaScript events events are associated with many elements of a page blah… events associated with click, double-click, focus, errors keyboard, hover, mousemove, resize, scroll,… return false to cancel the default action (submitting a form, following a link, etc) events will be fired all the way up the chain (e.g. li, then ul, then div, then document…)

School of Computing and Information Systems CS 371 Web Application Programming innerHTML replace the content of a tag with html code example: var obj=document.getElementById(“myId”); obj.innerHTML=“ wassup ”

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM JavaScript built-in objects Intro to the DOM collections methods techniques: insert html modify table or list values change structure of tables or lists change form elements

School of Computing and Information Systems CS 371 Web Application Programming Document Object Model contains collections, objects, methods collections: anchors[ ] - all anchor tags forms[ ] - information about forms images[ ] - about images links[ ] - includes and tags objects (document.cookie,.title, etc.) methods like getElementsByTagName

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document methods document.write inserts text in the web page data is written at the point it is executed document.open, close open starts a new document close ends it and displays the new document

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document properties document.cookie – saw this earlier document.domain document.readyState is the page still loading? document.title document.domain others…

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document methods (cont.) document.getElementsByTagName document.getElementById document.getElementsByName example in javascript: document.getElementById(“x”).innerHTML= “ wow ” in html:

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document methods (cont.) assign to objects: var divObj=document.getElementById(“x”); divObj.innerHTML=“stuff” properties: attributes[ ] childNodes[ ] firstChild nodeValue style many others…

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document methods (cont.) attributes var divObj=document.getElementById(“x”); if(divObj.attributes[0].nodeName==“alt”); alert(divObj.attributes[i].nodeValue); divObj.setAttribute(“class”,”pizzaz”); divObj.removeAttribute(“align”);

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM document methods (cont.) child elements: var divObj=document.getElementById(“x”); alert(divObj.childNodes[0].nodeValue); for(var i=0; i<divObj.childNodes.length; i++) divObj.removeChild(0); divObj.appendChild(document.createElement (“p”)); var txt=document.createTextNode(“Stuff”); divObj.childNodes[0].appendChild(txt);

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM table properties table properties cells[ ] rows[ ] border, bgColor, etc tr properties cells[ ] methods table: insertRow(x), deleteRow(x), moveRow tr: insertCell, deleteCell

School of Computing and Information Systems CS 371 Web Application Programming JavaScript DOM table examples insert rows var tab=document.getElementsByTagName (“table”)[0]; var myRow=tab.insertRow(-1); var myCell=myRow.insertCell(0); myCell.appendChild( document.createTextNode(“cell data”)); delete rows tab.deleteRow(0);