SlideShare a Scribd company logo
Nadar Saraswathi College of Arts & Science,
Theni.
DOM Collections
By,
S.Subha Thilagam
HTMLCollection Object
• The getElementsByTagName() method returns
an HTMLCollection object.
• An HTMLCollection object is an array-like list
(collection) of HTML elements.
• The following code selects all <p> elements in
a document:
Example:
var x =document.getElementsByTagName("p");
Contind..
• The elements in the collection can be accessed
by an index number.
• To access the second <p> element you can
write:
• y = x[1];
Note: The index starts at 0.
HTMLCollection Length
• The length property defines the number of
elements in an HTMLCollection:
Example:
var myCollection =
document.getElementsByTagName("p");
document.getElementById("demo").innerHT
ML = myCollection.length;
Example
• Change the background color of all <p>
elements:
var myCollection =
document.getElementsByTagName("p");
var i;
for (i = 0; i < myCollection.length; i++)
{
myCollection[i].style.backgroundColor = "re
d";
}
JavaScript Events
• HTML events are "things" that happen to
HTML elements.
• When JavaScript is used in HTML pages,
JavaScript can "react" on these events.
HTML Events
• An HTML event can be something the browser
does, or something a user does.
• Here are some examples of HTML events:
• An HTML web page has finished loading
• An HTML input field was changed
• An HTML button was clicked
• Often, when events happen, you may want to
do something.
Example:
<button onclick="document.getElementById('de
mo').innerHTML = Date()">The time
is?</button>
• In the example above, the JavaScript code
changes the content of the element with
id="demo".
Common HTML Events
Event Description
• Onchange An HTML element has been
changed
• Onclick The user clicks an HTML
element
• Onmouseover The user moves the mouse over an
HTML element
• Onmouseout The user moves the mouse away
from an HTML element
• Onkeydown The user pushes a keyboard key
• Onload The browser has finished loading the page
What can JavaScript Do?
• Things that should be done every time a page
loads
• Things that should be done when the page is
closed
• Action that should be performed when a user
clicks a button
• Content that should be verified when a user
inputs data
WEB PROGRAMMING ANALYSIS

More Related Content

PDF
Javascript and DOM
PPT
Ajax Introduction
PPT
Lewis Chiu Portfolio
PPT
Grails66 web service
PPTX
javaScript and jQuery
PPTX
OX Documents Explained
PDF
Pracitcal AJAX
Javascript and DOM
Ajax Introduction
Lewis Chiu Portfolio
Grails66 web service
javaScript and jQuery
OX Documents Explained
Pracitcal AJAX

Similar to WEB PROGRAMMING ANALYSIS (20)

PPTX
Dom date and objects and event handling
PPTX
Javascript part 2 DOM.pptx
DOCX
DOM(Document Object Model) in javascript
PPTX
WEB TECHNOLOGY Unit-4.pptx
PPTX
Unit-III_JQuery.pptx engineering subject for third year students
PPTX
Web Technology Part 3
PPTX
Web technologies-course 09.pptx
PDF
Client-side JavaScript
PPTX
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
PPTX
DOM (document Object Model) in java Script).pptx
PPTX
Xml part 6
PPTX
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
PPT
Javascript dom event
PPTX
Javascript 2
PPTX
FYBSC IT Web Programming Unit III Events and Event Handlers
PPTX
Part 7
PPT
Ddpz2613 topic9 java
PPTX
Dom(document object model)
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
Dom date and objects and event handling
Javascript part 2 DOM.pptx
DOM(Document Object Model) in javascript
WEB TECHNOLOGY Unit-4.pptx
Unit-III_JQuery.pptx engineering subject for third year students
Web Technology Part 3
Web technologies-course 09.pptx
Client-side JavaScript
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
DOM (document Object Model) in java Script).pptx
Xml part 6
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
Javascript dom event
Javascript 2
FYBSC IT Web Programming Unit III Events and Event Handlers
Part 7
Ddpz2613 topic9 java
Dom(document object model)
JavaScript - Chapter 12 - Document Object Model
Ad

More from sweetysweety8 (20)

PPTX
Artificial neural network
PPTX
Compiler Design
PPTX
Software engineering
PPTX
Software engineering
PPTX
WEB PROGRAMMING ANALYSIS
PPTX
Software engineering
PPTX
Software engineering
PPTX
Compiler Design
PPTX
WEB PROGRAMMING
PPTX
Bigdata
PPTX
BIG DATA ANALYTICS
PPTX
BIG DATA ANALYTICS
PPTX
Compiler Design
PPTX
WEB PROGRAMMING
PPTX
BIG DATA ANALYTICS
PPT
Data mining
PPTX
Operating System
PPTX
Relational Database Management System
PPTX
Relational Database Management System
PPTX
Relational Database Management System
Artificial neural network
Compiler Design
Software engineering
Software engineering
WEB PROGRAMMING ANALYSIS
Software engineering
Software engineering
Compiler Design
WEB PROGRAMMING
Bigdata
BIG DATA ANALYTICS
BIG DATA ANALYTICS
Compiler Design
WEB PROGRAMMING
BIG DATA ANALYTICS
Data mining
Operating System
Relational Database Management System
Relational Database Management System
Relational Database Management System
Ad

Recently uploaded (20)

PPTX
Tablets And Capsule Preformulation Of Paracetamol
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
Human Mind & its character Characteristics
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
2025-08-10 Joseph 02 (shared slides).pptx
PPTX
water for all cao bang - a charity project
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PPTX
Tour Presentation Educational Activity.pptx
PPTX
worship songs, in any order, compilation
PPTX
Anesthesia and it's stage with mnemonic and images
PPTX
Hydrogel Based delivery Cancer Treatment
PPTX
Relationship Management Presentation In Banking.pptx
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
PDF
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
PDF
natwest.pdf company description and business model
PPTX
lesson6-211001025531lesson plan ppt.pptx
Tablets And Capsule Preformulation Of Paracetamol
The Effect of Human Resource Management Practice on Organizational Performanc...
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
Human Mind & its character Characteristics
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
2025-08-10 Joseph 02 (shared slides).pptx
water for all cao bang - a charity project
Impressionism_PostImpressionism_Presentation.pptx
Tour Presentation Educational Activity.pptx
worship songs, in any order, compilation
Anesthesia and it's stage with mnemonic and images
Hydrogel Based delivery Cancer Treatment
Relationship Management Presentation In Banking.pptx
oil_refinery_presentation_v1 sllfmfls.pdf
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
Instagram's Product Secrets Unveiled with this PPT
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
natwest.pdf company description and business model
lesson6-211001025531lesson plan ppt.pptx

WEB PROGRAMMING ANALYSIS

  • 1. Nadar Saraswathi College of Arts & Science, Theni. DOM Collections By, S.Subha Thilagam
  • 2. HTMLCollection Object • The getElementsByTagName() method returns an HTMLCollection object. • An HTMLCollection object is an array-like list (collection) of HTML elements. • The following code selects all <p> elements in a document: Example: var x =document.getElementsByTagName("p");
  • 3. Contind.. • The elements in the collection can be accessed by an index number. • To access the second <p> element you can write: • y = x[1]; Note: The index starts at 0.
  • 4. HTMLCollection Length • The length property defines the number of elements in an HTMLCollection: Example: var myCollection = document.getElementsByTagName("p"); document.getElementById("demo").innerHT ML = myCollection.length;
  • 5. Example • Change the background color of all <p> elements: var myCollection = document.getElementsByTagName("p"); var i; for (i = 0; i < myCollection.length; i++) { myCollection[i].style.backgroundColor = "re d"; }
  • 6. JavaScript Events • HTML events are "things" that happen to HTML elements. • When JavaScript is used in HTML pages, JavaScript can "react" on these events.
  • 7. HTML Events • An HTML event can be something the browser does, or something a user does. • Here are some examples of HTML events: • An HTML web page has finished loading • An HTML input field was changed • An HTML button was clicked • Often, when events happen, you may want to do something.
  • 8. Example: <button onclick="document.getElementById('de mo').innerHTML = Date()">The time is?</button> • In the example above, the JavaScript code changes the content of the element with id="demo".
  • 9. Common HTML Events Event Description • Onchange An HTML element has been changed • Onclick The user clicks an HTML element • Onmouseover The user moves the mouse over an HTML element • Onmouseout The user moves the mouse away from an HTML element • Onkeydown The user pushes a keyboard key • Onload The browser has finished loading the page
  • 10. What can JavaScript Do? • Things that should be done every time a page loads • Things that should be done when the page is closed • Action that should be performed when a user clicks a button • Content that should be verified when a user inputs data