document.getElementById Used to change anything in your document (web page) that has an id Then you can change different aspects of the element with that.

Slides:



Advertisements
Similar presentations
function coffeeinfo() { document.getElementById('p3').innerHTML = "The word 'coffee' was.
Advertisements

Unit 3 Day 4 FOCS – Web Design. No Journal Entry.
Cascading Style Sheets
CSS CSS Precise Aesthetic Control. Cascading Style Sheets Though they can be put in HTML header, usually a separate page that the HTML links to Contains.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
HTML – A Brief introduction Title of page This is my first homepage. This text is bold  The first tag in your HTML document is. This tag tells your browser.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
End User Computing An Introduction to CSS Sujana Jyothi Research Lab1, Callan Building, Department of Computer Science
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
CS4370/6370 Web Development Cascading Style Sheets (CSS)
Cascading Style Sheets SP.772 May 6, CSS Useful for creating one unified look for an entire web site. Helps to seperate style from content. Can.
Information Technology Center Hany Abdelwahab Computer Specialist.
More HTML Chapter 4. 2 Nesting Tags How do you write the following in HTML? The wrong way: This is really, REALLY fun ! Tags must be correctly nested.
4.01 Cascading Style Sheets
Using color and fonts in HTML and XHTML Please use speaker notes for additional information!
HTML. Goals How to use the Komodo editor HTML coding and testing Basic HTML tags List and Images Tables and Links At least 2 pages and navigation
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.
FINAL EXAM REVIEW WEB TECH. JUST CLICK… THE CORRECT ANSWER WILL APPEAR WHEN YOU CLICK. GOOD LUCK!
HIGHER COMPUTING CSS. WHAT IS CSS? CSS: Cascaded Style Sheets used to separate a web site’s content(information) from its style(how it looks).
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
CSS Dvijesh Bhatt.
Image Use. Agenda Ordinary display of image: height, width, alt Rollovers Images as links (remove blue surround) Background images: stretch, tile, xonly/yonly.
DIY Web Development Hand Code Your Own Page (For Free!) by Bryan Brown, Indiana University Bloomington SLIS.
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
 HTML stands for Hyper Text Mark-up Language. The coding language used to create documents for the World Wide Web  HTML is composed of tags. HTML tags.
ITEC 745 Instructional Web Authoring I Instructor: Ray Cole Week 8.
IDs versus Classes Naming Your Tags for Maximum Functionality.
More Basic HTML. Add spacing (single & double space) Save Refresh Add horizontal rule Add comments Add styles Add headings Add features Add alignments.
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.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
15.2 More Basic HTML. More Basic HTML Add spacing (single & double space) Save Refresh Add horizontal rule Add comments Add styles Add headings Add features.
JMD2144 – Lesson 4 Web Design & New Media.
Just A Few More Fun Objectives 1 Having Some Fun With Java Script 2 Using Style Sheets.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
Unit 2, cont. September 12 More HTML. Attributes Some tags are modifiable with attributes This changes the way a tag behaves Modifying a tag requires.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
CSS Cascading Style Sheets. CSS Advantages Greater typography and page layout control Style is separate from structure Styles can be stored in a separate.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Lesson 03 // Cascading Style Sheets. CSS Stands for Cascading Style Sheets. We’ll be using a combination of Html and CSS to create websites. CSS is a.
More CSS.
 HTML is hypertext markup language. It is a way for people to display their information with more complex pictures and text displays. Before HTML, messages.
Definition CSS “Short for Cascading Style Sheets, a new feature being added to HTML that gives both Web site developers and users more control over how.
So far, we have looked at CSS selectors that correlate with HTML tags Now, we’ll see how you can define your own selectors using class and ID selectors.
CSS with XHTML Please use speaker notes for additional information!
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
JavaScript Challenges Answers for challenges
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Cascading Style Sheets Web Design Fairport High School.
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations Slide Set #4: CSS.
Spiderman ©Marvel Comics Creating Web Pages (part 1)
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
HTML HTML stands for Hyper Text Markup Language. HTML is used in making the base of a Website You can just use an online website maker like weebly.com.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Adding JavaScript ( ) JavaScript Guidelines document.write(" Hello World! ") Link Note: Try this without the tag.
CS 120: Introduction to Web Programming Lecture 10: Extra Features and Website Design Part 1 Tarik Booker CS 120 California State University, Los Angeles.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
Revised June 2008 Online PD Basic HTML1 Let’s Try It!  Open Notepad oStart > All Programs > Accessories > Notepad oDon’t get WordPad by mistake – won’t.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
InnerHTML: This is a paragraph about Ted the cat What is the innerHTML of ‘cat’? zombies
Introduction to.
Javascript Game Assessment
Web Programming and Design
Presentation transcript:

document.getElementById Used to change anything in your document (web page) that has an id Then you can change different aspects of the element with that id: You can use document.getElementById to change the: src height width alt (technically, you can even change the id, but as a rule, don’t)

We can use getElementById to change CSS style: This is a paragraph This is a second paragraph document.getElementById("firstp").style.color = "#9999FF"; document.getElementById("firstp").style.fontSize = "120%"; document.getElementById("firstp").style.backgroundColor="#332277"; document.getElementById("firstp").style.textAlign = "right"; document.getElementById("firstp").style.padding = "30px"; document.getElementById("firstp").style.borderWidth = "8px"; document.getElementById("firstp").style.borderColor = "green"; document.getElementById("firstp").style.borderStyle = "inset"; link

Other styles you can change using getElementById backgroundColor backgroundImage backgroundPosition backgroundRepeat borderColor borderStyle borderWidth margin padding width position color fontFamily fontSize fontWeight fontStyle lineHeight textAlign And more…

What if we want to change the text? This is a paragraph This is a second paragraph var x = confirm("Do you want to see new text?") if (x == true) { document.getElementById("firstp").innerHTML = "Some new text"; } Two new coding elements: innerHTML and the confirm button link

innerHTML The innerHTML is what is between the opening and the closing tag, regardless of what the tag is: This is the innerHTML text because it goes between the opening and closing tag Above, the innerHTML is: “This is the innerHTML text because it goes between the opening and closing tag” To change it: document.getElementById(“firstp”).innerHTML = “new text for paragraph” Title goes here Above: innerHTML is: Title goes here To change: document.getElementById(“firsth”).innerHTML = “New Title”

innerHTML (cont.) link to udel What is the innerHTML of linked? What is the innerHTML of firstlink? How would you change the innerHTML of linked to a new link? cats dogs What is the innerHTML of list1? What is the innerHTML of firstitem? How would you change the innerHTML of list1 to a new list?

Confirm box The confirm box is like the prompt box, only in this case you only have the choice of choosing “ok” or “cancel”. var x = confirm(“Do you want to change something?”) If you choose ok, x holds true If you choose cancel, x holds false Aside: true and false are known as Boolean values var x=confirm("Press a button") if (x==true) {document.write(“p1”).innerHTML="You pressed OK!" } else {document.write(“p1”).innerHTML ="You pressed Cancel!“ }

Learn about animals You can learn so much about every animal in the zoo! var animals = new Array() animals[0] = "lions" animals[1] = "giraffes" animals[2] = "penguins" animals[3] = "polar bears" var pics = new Array() pics[0] = "Images/lion.jpg" pics[1] = "Images/giraffe.jpg" pics[2] = "Images/penguin.jpg" pics[3] = "Images/polarbear.jpg" var info = new Array() info[0] = "Lions are the second largest big cat species in the world (behind tigers). The roar of a lion can be heard from 8 kilometers (5.0 miles) away." info[1] = "A male giraffe can weigh as much as a pick up truck! Although a giraffe’s neck is 1.5 – 1.8 metres, it contains the same number of vertebrae at a human neck." info[2] = "Penguins spend around half their time in water and the other half on land. Penguins spend around half their time in water and the other half on land." info[3] = "Polar bears keep warm thanks to nearly 10 cm of blubber under the skin. Polar bears have black fur under their outer layer of white fur." var x = confirm("Would you like to learn about an animal?") if (x == true) { var num = Math.floor(Math.random()*4) document.getElementById("animal").innerHTML = animals[num]; document.getElementById("pic1").src = pics[num]; document.getElementById("firstp").innerHTML = info[num]; } link

Comments A way of including comments to yourself and to other people without the browser caring. Comments start with /* and end with */. Everything between these opening and closing markers is ignored by the browser so anything between them won’t be run by javascript. /* This script asks the user for a number. It uses that number to set the element with the id “ball1” to the width of the number the user entered */ var x = parseInt(prompt("What size should the ball's width be?")) document.getElementById("ball1").width = x Comments are designed for leaving information for people to read (as opposed to the browser) But we can use comments to isolate what code is working and what isn’t

Debugging: You've got a problem – your code doesn't work. There is a "bug“* in your code. (something that isn't correct Could be a typo (most likely!!) Could be a "syntax error" e.g., document.getElementbById('pic1).src = "cat.jpg"; e.g., forgetting an opening or closing { } or ( ) e.g., if (par1 = 'pic1') Could be a logic error These are the hardest to find! When what you're trying to do won't be done in the way you're trying to do it. How do you find the "bug"?? *Aside: the term debugging came from radio repairmen from before WWII. In fixing radios, the repairmen often had to clean out bug carcases in order to get the radios working.

Finding the bug (Debugging) 1.Is your web site showing up as you want it to? Probably an html error 1.Make sure the page is valid (you’ve got an opening and closing tag and an opening and closing tag inside it. 2.Check to make sure that if you opened a tag, you closed it properly. Next, check to make sure everything opened is closed 1.Make sure your quotes (" ") open and close properly 1.Make sure the quotes are " " and not “” (from copying from ppt or word) 2.Go through and check for opening and closing () and {} 3.CHECK CAREFULLY FOR PROPER CAPITALIZATION 4.If nothing shows up, check to make sure you've properly entered,

To isolate where the bug is, use comments: Do you need a coat in Europe? Find out here! var ctemp = parselnt(prompt("What is the temperature (in Celsius?")) var ftemp = (9/5) * ctemp + 32 if (ftemp >= 20) {document.getElementById(‘p1’).innerHTML = "You'll need a coat and hat } else if (ftemp => 45) { document.getElementById(‘p1’).innerHTML =“You'll need a light coat" } else if (ftemp >=60) { document.getElementById(‘p1’).innerHTML ==“You'll need a sweater" } else if (ftemp >= 70) { document.getElementByID(‘p1’).innerHTML =“ You're good without a coat" }

Comments/Debugging Learn about animals You can learn so much about every animal in the zoo! var animals = new Array() animals[0] = "lions" animals[1] = "giraffes" animals[2] = "penguins" animals[3] = "polar bears" var pics = new Array() pics[0] = "Images/lion.jpg" pics[1] = "Images/giraffe.jpg" pics[2] = "Images/penguin.jpg" pics[3] = "Images/polarbear.jpg" var info = new Array() info[0] = "Lions are the second largest big cat species in the world (behind tigers). The roar of a lion can be heard from 8 kilometers (5.0 miles) away." info[1] = "A male giraffe can weigh as much as a pick up truck! Although a giraffe’s neck is 1.5 – 1.8 metres, it contains the same number of vertebrae at a human neck." info[2] = "Penguins spend around half their time in water and the other half on land. Penguins spend around half their time in water and the other half on land." info[3] = "Polar bears keep warm thanks to nearly 10 cm of blubber under the skin. Polar bears have black fur under their outer layer of white fur." var x = confirm("Would you like to learn about an animal?") if (x == true) { var num = Math.floor(Math.random()*4) document.getElementById("animal").innerHTML = animals[num]; document.getElementById("pic1").src = pic[num]; document.getElementById("firstp").innerHTML = info[num]; }

Functions Remember this? Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the javascript inside a function, with a name, and then “call” the function again and again and again. Learn about animals You can learn so much about every animal in the zoo! var animals = new Array() animals[0] = "lions" animals[1] = "giraffes" animals[2] = "penguins" animals[3] = "polar bears" var pics = new Array() pics[0] = "Images/lion.jpg" pics[1] = "Images/giraffe.jpg" pics[2] = "Images/penguin.jpg" pics[3] = "Images/polarbear.jpg" var info = new Array() info[0] = "Lions are the second largest big cat species in the world (behind tigers). " info[1] = "A male giraffe can weigh as much as a pick up truck!" info[2] = "Penguins spend around half their time in water and the other half on land. " info[3] = "Polar bears keep warm thanks to nearly 10 cm of blubber under the skin. " var x = confirm("Would you like to learn about an animal?") if (x == true) { var num = Math.floor(Math.random()*4) document.getElementById("animal").innerHTML = animals[num]; document.getElementById("pic1").src = pics[num]; document.getElementById("firstp").innerHTML = info[num]; }

Defining a function function fname () { code that function does } Fname is the name you give your function. The { and } start and end the function You put whatever you want to happen in between { and }

Example: This is a paragraph function changestyle() {document.getElementById('firstp').style.color = "#FFFFFF"; document.getElementById('firstp').style.backgroundColor = "#000000"; document.getElementById('firstp').style.fontFamily = "arial"; } link

Example: This is a paragraph function changestyle() {document.getElementById('firstp').style.color = "#FFFFFF"; document.getElementById('firstp').style.backgroundColor = "#000000"; document.getElementById('firstp').style.fontFamily = "arial"; } link

Functions (continued) Functions do not execute automatically So far, the code we have written executed when we click on the button Functions ONLY execute when our code calls them Functions can go in the head section of our html code or in the body We usually put them in the head section Reason: if there are images involved, by putting it in the head section, the images will preload. If we put the code in the body section, the images won’t download until the function is called, making it run slow. Plus, it is just sloppier

Naming Functions Like variables: No spaces!!!!! No special characters Cannot start with a number Cannot be the same name as a variable you’re using Cannot be the same name as something that javaScript already uses.

function show_confirm() { var r=confirm("Press a button"); if (r==true) { document.getElementById('p1').innerHTML = "You pressed OK!"; } else { document.getElementById('p1').innerHTML = "You pressed Cancel!"; } Answer goes here link

function show_pref() { var color = prompt("Please enter your favorite color!", ""); if (color == "purple") { document.getElementById('p1').innerHTML="You are artistic and moody! " } else if (color == "blue") { document.getElementById('p1').innerHTML="You are serene and calm." } else if (color == "red") { document.getElementById('p1').innerHTML="You are fiery and passionate!" } else if (color == "green") { document.getElementById('p1').innerHTML="You are earthy and comfortable." } color transcript Your info will go here Thanks for playing! link