>> JavaScript: Document Object Model

Slides:



Advertisements
Similar presentations
Table (TABLE) Contains TABLE ROWS (TR) Contains TABLE DATA (TD) Data can contain anything Text Lists Other tables Pictures …
Advertisements

CSS The basics { }. CSS Cascading Style Sheets - language used to – describe html appearance & formatting Style Sheet - file that describes – how html.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
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 stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Principles of Web Design 5 th Edition Chapter Nine Site Navigation.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Introducing Cascading Style Sheets  Cascading Style Sheet Basics  Creating Styles  Using Styles  Manipulating Styles  Text Formatting with CSS.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JS: Document Object Model (DOM)
INTERNAL CSS Casey Ames Different types of CSS There are three different types of CSS: ◦ External CSS ◦ Internal CSS ◦ Inline CSS In this presentation.
DOM and JavaScript Aryo Pinandito.
>> Introduction to HTML: Tables. HTML is used to give websites structure 5 Basic Tags Element = Start-Tag+Content+End-Tag Heading Tags [h1-h6] Paragraph.
CITS1231 Web Technologies JavaScript and Document Object Model.
WRT235: Writing in Electronic Environments Basic CSS.
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.
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.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Introducing Cascading Style Sheets. Cascading Style Sheet Basics  Cascading Style Sheet Basics  Creating Styles  Using Styles  Manipulating Styles.
>> More on CSS Selectors. Pre-requisite Open the file called sample.txt Copy the all the text from the file Open your browser and go to codepen.io Paste.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Are You Smarter Than a 5 th Grader? 1,000,000 5th Grade HTML 5th Grade Syntax 4th Grade HTML 4th Grade Syntax 3rd Grade HTML 3rd Grade Syntax 2nd Grade.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
Create Element, Remove Child. The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
XML DOM Week 11 Web site:
Java Script and the DOM DOM stands for: –The Document Object Model When a browser reads a web page, it converts it’s contents from HTML into a hierarchical.
CSS (Cascading Style Sheets). CSS CSS – Cascading Style Sheets – Cascade because of the way CSS rules can stack on top of each other. Allows you to add.
WEB FOUNDATIONS CSS Overview. Outline  What is CSS  What does it do  Where are styles stored  Why use them  What is the cascade effect  CSS Syntax.
CSS.
Cascading Style Sheets (CSS)
>> Form Data Validation in JavaScript
Web Basics: HTML/CSS/JavaScript What are they?
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Unit M Programming Web Pages with
LAB Work 01 MBA 61062: E-Commerce
The Box Model in CSS Web Design – Sec 4-8
>> Introduction to CSS
>> HTML: Tables.
CGS 3066: Web Programming and Design Spring 2017
Applied Online Programming
CS 371 Web Application Programming
DOM Robin Burke ECT 360.
Cao Yuewen SEEM4570 Tutorial 03: CSS Cao Yuewen
>> The “Box” Model
>> More on CSS Selectors
Concepts of HTML, CSS and Javascript
Unit M Programming Web Pages with
Intro to Web Development Class A Review
Intro to CSS CS 1150 Fall 2016.
>> CSS Layouts.
Intro to CSS CS 1150 Spring 2017.
CSS – Cascading Style Sheet DOM – Document Object Model
TOPICS Chrome Dev Tools Process for Building a Static Website
Week 11 Web site: XML DOM Week 11 Web site:
HTML A brief introduction HTML.
Software Engineering for Internet Applications
>> Dynamic CSS Selectors
Cascading Style Sheets Color and Font Properties
Working with Dynamic Content and Styles
© 2015, Mike Murach & Associates, Inc.
Document Object Model (DOM): Objects and Collections
Sensemaking Course Catalog.
Javascript and JQuery SRM DSC.
Sensemaking Course Catalog.
Murach's JavaScript and jQuery (3rd Ed.)
Web Programming and Design
Web Programming and Design
Presentation transcript:

>> JavaScript: Document Object Model

WHAT IS DOM?

Web-based Systems | Misbhauddin

NO HTML you write is parsed by the browser and turned into the DOM Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin NO View Source just shows you the HTML that makes up that page. It's probably the exact HTML that you wrote Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin YES But…………….. Web-based Systems | Misbhauddin

When is the DOM different than the HTML? There are mistakes in your HTML and the browser has fixed them I told you browsers are intelligent Example Try creating a table element without the thead and tbody See what happens Web-based Systems | Misbhauddin

Document Object Model (DOM) <p title="The test paragraph">This is a sample of some <b>HTML you might <br>have</b> in your document</p> p title ChildNodes attributes This is a sample of some The test paragraph b in your document ChildNodes HTML you might have br Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin DOM Root window document Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Parts of the DOM tree Known as nodes Different types of nodes Element Nodes P, BR, B Text Nodes Text strings inside of an element Collections ChildNodes, attributes Attribute Nodes Attribute name and value Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin White Space Nodes Whitespace symbols in the HTML are recognized as the text and become text nodes If you do not want any whitespace nodes <!DOCTYPE HTML><html><head><title>Title</title></head><body></body></html> Web-based Systems | Misbhauddin

Walking the DOM OR Traversing the DOM

Web-based Systems | Misbhauddin Select a Node Three ways Using an ID Using the Tag Name (Element Name) Using the Class Name (old) Using the Name Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Pre-requistie Download and open the file called dom.html Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Get Element By ID document.getElementById() Returns one element WHY? Try Now Select the element with id = “test” in the given sample Web-based Systems | Misbhauddin

Get Elements By ClassName document.getElementsByClassName() Returns an array. Why? Try Now Select the element with class = “hidden” in the given sample Web-based Systems | Misbhauddin

Get Elements By Tag Name document.getElementsByTagName() Returns an array. Why? Try Now Select all the paragraph elements in the given sample document Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Get Elements By Name document.getElementsByName() Returns an array. Why? Try Now Select the element with the name = “gender” Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin What Now? I have selected all the elements, now what You can change the properties (CSS) of the element You can get the value of the element (form) You can set the value of the element You can add content inside the element You can add, delete or update element / attributes / text Web-based Systems | Misbhauddin

Change property of an element in JS

Web-based Systems | Misbhauddin Two ways Using the style property (can only be used for CSS Styles) First select the element Use the property var a = document.getElementBy………. a.style.propName = newValue; Using the setAttribute Method First select the element Use the method var a = document.getElementBy………. a.setAttribute(‘attributeName’,newValue); Web-based Systems | Misbhauddin

Using Properties from CSS There are some properties with ‘-’ Example border-right, font-size, text-align You cannot use a ‘-’ in JavaScript when using the style Use Camel Case It means, the first letter after the ‘-’ is made capital and the ‘-’ is removed border-right -----> borderRight text-align --------> text-align Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Do Now Change the color of the 2nd paragraph to “red” Change the element with id=“test” to font size as 50px Display None for the element with name = “gender” Web-based Systems | Misbhauddin