Changing CSS Styles via JavaScript No readings?. 2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing.

Slides:



Advertisements
Similar presentations
Style changes (contd.) When a user event happens in the context of some element, we may wish several aspect of the style to change For example, we may.
Advertisements

Part 2 Introduction to CSS. CSS Syntax – class selector 1 With the class selector you can define different styles for the same type of HTML element. You.
Making Things Look Nice: Visual Appearance and CSS CMPT 281.
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.
DOM and timers CS Problems with JavaScript JavaScript is a powerful language, but it has many flaws:  the DOM can be clunky to use  the same code.
Chapter 6 © 2012 by Addison Wesley Longman, Inc Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element.
Tutorial 3 Introducing Cascading Style Sheets. XP New Perspectives on Blended HTML, XHTML, and CSS2 Objectives Learn about Cascading Style Sheets Write.
Starting BBEdit (Notepad) and Opening an HTML File Open the Public Folder Start Notepad or BBEdit Click File on the menu bar, and then click Open In the.
1 JavaScript Document Object Model & Events. 2 Document Object Model (DOM) JavaScript access to the elements of an HTML document. An object hierarchy.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
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).
CHAPTER 24 PERFORMING CSS TRANSITIONS AND ANIMATIONS.
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 Concepts and Techniques Fourth Edition Project 8 Creating Style Sheets.
HTML/CSS Hyper Text Markup Language. CSS Cascading Style Sheets.
W. W. Milner JavaScript. W. W. Milner Chapter 1 - Intro Why use JavaScript? Interactivity LiveScript JavaScript Jscript ECMAScript JavaScript is not Java!
Scripting Languages.
DOM and timers CS Problems with JavaScript JavaScript is a powerful language, but it has many flaws:  the DOM can be clunky to use  the same code.
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Dynamic Documents With JavaScript.
I NTRO TO CSS IAT100 Spring I NTRO TO CSS Covered in this lesson: Overview What is CSS? Why to use CSS? CSS for Skinning your Website Structure.
Using Cascading Style Sheet As you create more web pages, you may wish to impose a consistent look for all of your web pages or for group of related pages.
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
Working with Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 5.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
1 Lesson 3 Power Techniques HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
Form Tag How to use Form Tag Something NEW ? PARAMETER Attribute NAME Specifies the name for a form To specify which form to submit with JavaScript, this.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 20 – Dynamic HTML: Object Model and Collections Outline 20.1Introduction 20.2Object Referencing.
Chapter 7: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
CSE 154 Lecture 20: The DoM tree.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming images.
Advanced Web Development Instructor: Thomas Bombach.
Colors & Fonts Building a Website Lesson 7. Font Font The tag specifies the font face, font size, and color of text. The tag can have any or all of these.
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.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Cascading Style Sheets
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
Lecture 2: Cascading Style Sheets (CSS) Instructor: Dr. M. Anwar Hossain.
EIW: Javascript DOM and Events1 JavaScript Document Object Model & Events.
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
Host Objects: Browsers and the DOM
How to… Cascading Style Sheets. How to Insert a Style Sheet When a browser reads a style sheet, it will format the document according to it. There are.
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Tutorial 11 1 JavaScript Operators and Expressions.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
Link. setTimeout() What if you want to automatically cycle through the pics? So you don’t have to keep clicking the button to see the next pic Use the.
CIS 228 The Internet 11/17/11 Of Timers and Cookies.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 15 – Dynamic HTML: Object Model and Collections Outline 15.1Introduction 15.2Object Referencing.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
Project 7: Exploring DHTML Essentials for Design JavaScript Level Two Michael Brooks.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript and Ajax (JavaScript Dynamic HTML (DHTML)) Week 7 Web site:
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
Chapter 13: DHTML: Object Model and Collections CIS 275—Web Application Development for Business I.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Introduction to.
HTML & teh internets.
Key concepts of Computing
Document Object Model (DOM): Objects and Collections
Web Systems Development (CSC-215)
Functions, Regular expressions and Events
Web Programming and Design
Web Programming and Design
Presentation transcript:

Changing CSS Styles via JavaScript No readings?

2 Review? You can change the CSS styling of an element with JavaScript Syntax is similar to accessing an attribute:  document.getElementById(“id”).attribute; vs.  document.getElementById(“id”).style.property;

3 Review Property names in JavaScript replace hyphens with capital letters CSS properties: Properties in JavaScript: font-size, background-color, text-decoration fontSize, backgroundColor, textDecoration

4 HTML snippet: JavaScript file: This will show the size of the font in the paragraph Getting the Property Value There is some text here. <input type=“button” value=“Click” onclick=“showFontSize()”; /> function showFontSize() { var fontSize = document.getElementById(“text”).style.fontSize; alert(fontSize); }

5 HTML snippet: JavaScript file: This will change the font in the paragraph to size 20 font. Setting the Property Value There is some text here. <input type=“button” value=“Click” onclick=“increaseFont()”; /> function increaseFont() { document.getElementById(“text”).style.fontSize = “20pt”; }

6 Setting the Property Value NOTE! Whenever you set the value of a style property, you should use a string: function increaseFont() { document.getElementById(“text”).style.fontSize = 20pt; } function increaseFont() { document.getElementById(“text”).style.fontSize = “20pt”; }

7 Example Changing the color and size of text

Timers

9 Using Time in your Programs Repeat tasks every set time period.  Making a clock tick every second Do something after a delay  Click a button that shows an image, and then hide it after 5 seconds

10 Timer Functions in JavaScript Built in functions, like alert:  setTimeout – calls a function after a time delay  setInterval – calls a function every given time period  clearTimeout – stops the timer We will only look at the setTimeout function

11 setTimeout function Same as calling any other function with parameters:  setTimeout(function, delay);  function is the function to call after delay milliseconds has passed function startTimer() { setTimeout(alertBox, 1000); } function alertBox() { alert(“Hello!”); }

12 Important Note! The function parameter should be the name of the function you want to call with NO parentheses! Why? function startTimerGood() { setTimeout(alertBox, 1000); } function startTimerBad() { setTimeout(alertBox(), 1000); } function alertBox() { alert(“Hello!”); }

13 Example Countdown