JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
4.1 JavaScript Introduction
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
>> Introduction to JavaScript
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Tutorial 10 Programming with JavaScript
Using Client-Side Scripts to Enhance Web Applications 1.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
DHTML: Working with Objects Creating a Dynamic Web Page.
JavaScript - A Web Script Language Fred Durao
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
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.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
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.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Lesson 30: JavaScript and DHTML Fundamentals. Objectives Define and contrast client-side and server-side technologies used to create dynamic content for.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
Module 1 Introduction to JavaScript
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 6 JavaScript: Introduction to Scripting
Introduction to Scripting
Javascript Short Introduction By Thanawat Varintree,
Chapter 7 - JavaScript: Introduction to Scripting
DHTML Javascript Internet Technology.
JavaScript: Introduction to Scripting
DHTML Javascript Internet Technology.
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

JavaScript Objects - DOM CST 200 JavaScript

Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce document object Use document.write() method to output information on a web page

JavaScript Objects JavaScript is an object-based programming language – Programmer focuses on objects needed to solve a problem An object represents a real-world entity An object contains properties and methods – Properties are attributes that distinguish one object from another – Methods are functions or actions you want an object perform

Real World Objects Humans interact with objects in the real world Example: Imagine we have a Car object PropertiesMethods makestart() modelforward() mpgreverse() colorshutOff()

Real World Objects (2) Example: Imagine we have a Person object PropertiesMethods first_nameprintName() last_nameprintAge() date_of_birthshowAvatar() sendMessage()

Real World Objects Exercise Example: Imagine we are building a Checkers game for a website and we have a Checkers object. List some properties and methods: PropertiesMethods

dot Notation JavaScript uses the dot notation, which specifies the syntax (rule) for accessing the properties and methods of an object Syntax object.property object.method()

Document Object Model To manipulate HTML pages and elements within, web programmers need a model that identifies each HTML element and associated attributes Document Object Model (DOM) specification from World Wide Web Consortium (W3C) does this – Platform and language-neutral – Allows dynamic update to content and structure of web pages

Netscape Document Object Model

Document Object Model (cont) Document Object Model defines objects that correspond to webpage documents and elements within Objects have properties and methods, and respond to events Properties – specify attributes or characteristic of object Methods – specify functions object can perform Events – methods corresponding to user actions

document Object In the DOM, the document object represents the current document displayed by the browser – One of the most commonly used JavaScript objects – Any text, graphics or any information displayed on a web page is part of the document object – Common use of the document object is to add new text to a web page

document.write() method To write text to a Web page with JavaScript, use the method document.write(“text”); where text is the HTML code to be written to the Web page

document Object example #1 This script outputs “Hello World” to the browser Hello World JavaScript Example #1 <!– // output Hello World document.write(“Hello World”); --> Hello World JavaScript Example #1 <!– // output Hello World document.write(“Hello World”); --> 13

document Object example #2 document.write() method can output html tags that will be parsed and rendered as html elements by the web browser document.write(“ Introduction ”); document.write(“ ”); document.write(“ Introduction ”); document.write(“ ”);

window Object In the DOM, the window object represents the current browser window – In tabbed browsers, each tab contains its own window object – Provides properties and methods for manipulating the browser window – alert() method is used to display a message box – prompt() method is used to display a dialog box

window Object example #1 In the above statement, we are calling the alert() method of the window object We pass as an argument to the alert( ) method the the string “Welcome to JavaScript!” window.alert("Welcome to JavaScript!"); window.alert("Welcome to JavaScript!");

window Object example #2 This script displays a message in a popup window var name = 'Seth Freeman'; window.alert("Welcome " + name + " to the world of JavaScript!"); var name = 'Seth Freeman'; window.alert("Welcome " + name + " to the world of JavaScript!"); Declare and initialize variable name 17 Concatenate strings

window Object example #3 This script gets a string value from the user and displays a message with that value var name; name = window.prompt(“Whats your name stranger?”); window.alert("Welcome " + name + " to the world of JavaScript!"); var name; name = window.prompt(“Whats your name stranger?”); window.alert("Welcome " + name + " to the world of JavaScript!"); Declare the variable name 18 Concatenate strings Prompt user for name