Page Elements © Copyright 2014, Fred McClurg All Rights Reserved.

Slides:



Advertisements
Similar presentations
HTML and CSS. HTML Hyper Text Markup Language Tells browser how to display text and images.
Advertisements

getElementById() document.getElementById(“idName").innerHTML = “Any valid content"; getElementById is a method innerHTML is a property.
The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
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.
Document Object Model (DOM) JavaScript manipulation of the DOM.
FORMATTING IN CONTEXT. FOLLOW UPS ANCHOR POINTS MUST BE UNIQUE  If you have more than one, how does it know where to go?  They can be repeated across.
Cascading Style Sheets CSS. What is it? Another file format ! its not like html Describes the looks of “selectors” in a.css file (example.css) in the.
Lesson 12- Unit L Programming Web Pages with JavaScript.
1 Lesson 10 Using JavaScript with Styles HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
 CSS ids  Pages  Sites  HTML: class=“name”  Names may define format OR content › Either works  CAN apply multiple classes to the same tag  Multiple.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JavaScript, Third Edition
Introduction to HTML academy.zariba.com 1. Lecture Content 1.What is HTML? 2.The HTML Tag 3.Most popular HTML tags 2.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
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.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
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.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
18 People Surveyed HTML (HyperText Markup Language) HTML “tags” Describes structure Building blocks Headings, paragraphs, lists, links, images, quotes,
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.
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.
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.
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.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
Chapter 5: Windows and Frames
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
JQuery Introduction © Copyright 2014, Fred McClurg 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.
Event Handling © Copyright 2014, Fred McClurg All Rights Reserved.
JavaScript, Fourth Edition Chapter 4 Manipulating the Browser Object Model.
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.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
 Scripts that execute in response to some event  User clicking on something  Script does NOT execute as part of page loading  DOM facilities like.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript.
JavaScript Object Model. Biggest Advantage of JavaScript  I can access values of HTML elements using JavaScript  I can modify values of HTML elements.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Project 7: Exploring DHTML Essentials for Design JavaScript Level Two Michael Brooks.
Selective Formatting. Auto Grader Multiple selectors  May use the same formatting for two elements h1, h2 { font-family: cursive; }  Maintains consistency.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
THE DOM.
Introduction to JavaScript DOM and Events
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
>> Introduction to CSS
CGS 3066: Web Programming and Design Spring 2017
CS 371 Web Application Programming
CGS 3066: Web Programming and Design Spring 2016
Intro to JavaScript CS 1150 Spring 2017.
Web Development & Design Foundations with HTML5 7th Edition
Document Object Model (DOM): Objects and Collections
Web Systems Development (CSC-215)
Google Fonts Selective Formatting
Common Page Design Elements
Presentation transcript:

Page Elements © Copyright 2014, Fred McClurg All Rights Reserved

Getting a Handle on Elements Discussion: It is possible to reference and manipulate HTML elements from within JavaScript. In order to do so, you must retrieve a handle to the element. From this handle you can get information regarding the current attributes (color, size, etc.) of the element. You can also use this handle modify the element. 2

Getting Elements by ID Discussion: HTML elements that have an “id” attribute, can be retrieved via the document method “getElementById()”. The property “innerHTML” contains the content. Example: "Integrity is the main issue that makes the difference between a good leader and a bad one." -- John MacArthur var txt = document.getElementById( "quote" ); alert( txt.innerHTML ); // get content of 3 getElementById.html

Text clock via setInterval() Discussion: The function “setInterval()” executes a function repeatedly every specified time interval. Example: var textClock = document.getElementById( "clock" ); setInterval( function() { var now = new Date(); // current time var textStr = now.toLocaleTimeString(); textClock.value = textStr; // set text value }, 1000 ); // update every one second 4 setIntervalClock.html

Slideshow via setInterval() <img src="images/000.jpg" id="slideShow" style="float: left; margin: 0 7px 7px 0;" /> var theImage = document.getElementById( "slideShow" ); var imageList = [ "000.jpg", "001.jpg", "002.jpg", "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg" ]; var imageIndex = 1; // global index function rotateImage() { theImage.setAttribute( "src", "images/" + imageList[imageIndex] ); imageIndex++; if ( imageIndex >= imageList.length ) { imageIndex = 0; // start over with first } var intervalHandle = setInterval( rotateImage, 3000 ); // start timer theImage.onclick = function() { // add click event to image clearInterval( intervalHandle ); // remove timer on click }; 5 setIntervalSlideShow.html

Getting Elements by Tag Name Discussion: Multiple HTML elements with the same Tag Name can be retrieved via the document method “getElementsByTagName()”. Example: George Washington Carver Sir Isaac Newton Blaise Pascal var links = document.getElementsByTagName( "h2" ); for ( var i = 0; i < links.length; i++ ) { console.log( links[i].innerHTML ); // content } 6 getElementsByTagName.html

Getting Attributes via getAttribute() Discussion: An attribute of a HTML element can be retrieved via the “getAttribute()” method. Example: Centered Sub-Title... var subTitle = document.getElementById( "subHead" ); console.log( subTitle.getAttribute( "align" ) ); 7 getAttribute.html

In order to retrieve nested elements, it may require a combination of calls to “getElementById()” and “getElementsByTagName()”: First Item Second Item Third Item var parent = document.getElementById( "ulList" ); console.log( "Parent HTML:" + parent.innerHTML ); var child = parent.getElementsByTagName( "li" ); for ( var i = 0; i < child.length; i++ ) { console.log( "Child HTML:" + child[i].innerHTML ); } Getting Nested Elements 8 getNestedElem.html

An HTML Element attribute can be set via the “setAttribute()” method: Sub-Title Left Sub-Title Center Sub-Title Right var tagName = document.getElementsByTagName( "h2" ); tagName[0].setAttribute( "align", "left" ); tagName[1].setAttribute( "align", "center" ); tagName[2].setAttribute( "align", "right" ); var idName = document.getElementById( "leftHead" ); idName.setAttribute( "style", "color: red;" ); Setting Attributes via setAttribute() 9 setAttribute.html

The HTML content of an element can be set via the “innerHTML” property: var today = new Date(); var year = today.getFullYear(); var foot = document.getElementById( "footer" ); foot.innerHTML = "© Copyright " + year; Changing Content via innerHTML 10 innerHTML.html