SlideShare a Scribd company logo
1 of 10
Download to read offline
@Achieversit
JavaScript
DOM
Contact Us : 8151000080
E-mail : info@achieversit.com
#Dom
0
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
1
Hey Everyone's
In this post, you will learn about
JavaScript Document Object Model
(DOM) with the help of examples.
Do Like,save and Share This Post If You
Found This Helpful.
A Document object represents the HTML
document that is displayed in that window.
This document enables Javascript to access and
manipulate the elements and styles of a website.
By the help of document object ,we can add
dynamic content to our web page.
if you want access any object on your web page
you always start with the document.
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
2
DOM
window.document
// OR
document
The model is built in a tree structure of objects
and defines:
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
3
HTML elements as objects.
Properties and events of the HTML
Methods to access the HTML elements.
In this shot, we will learn different ways to select a
DOM element in JavaScript.
JavaScript provides six methods to select an
element from the document.
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
4
Select Elements
Get element by ID
Get elements by class name
Get elements by tag name
Get elements by name
Queryselector
Queryselectorall
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
5
Get element by ID :
The get ElementById() method is used to
get a single element by its id.
<p id="para">This is my first Paragraph</p>
const paragraph = document.getElementById("para1");
console.log(paragraph);
//<p id="para">This is my first paragraph </p>
Get elements by class name :
We can also get more than one object using the
getElementsByClassName() method which
returns an array.
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
6
Get element by tag name :
We can also get our elements by tag name
using the getElementsByTagName() method.
<p class="para">This is my first Paragraph</p>
<p class="para">This is my first Paragraph</p>
var paras= document.getElementByClassName("para1");
console.log(paras);
// HTML Collection(2)
// 0: p.para
// 1: p:para
// length:2
<ul>
<li>Coffee</li>
<li>Tea</li>
</ul>
const tagNodes= document.getElementByTagName("li");
console.log(tagNodes);
// HTML Collection(li,li)
// 0: li
// 1: li
// length:2
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
7
Get Elements By name :
The getElementsByName method returns the elements
that match the value of the name attribute with the
passed string. The return value is a live NodeList
Collection.
document.getElementByName("first-boy");
It is not recommended to use getElementByName
because it works differently on Internet Explorer.
Queryselector :
The querySelector() method returns the fiirst element that
matches a specified CSS selector.
That means that you can get elements by id,class,tag and all ot
valid CSS selectors.
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
8
var header = document.querySelector('#header'); // using id
var item = document.querySelector('.list-item'); // using class
var heading = document.querySelector('h1'); // using tag
var para = document.querySelector('div > p'); //
document.querySelector(Css Selectors);
Syntax :
QueryselectorAll :
The querySelectorAll() method is an extension of the
querySelector() method. This method returns all the
elements that match the passed selector.
We can send multiple selectors separated by commas.
document.querySelectorAll(".child");//returns all element with child class
<div id="parent-1" class="container">
<p>This is my paragraph</p>
<span>sp</span>
</div>
let e = document.querySelectorAll("span, p");
// [p, span]
@Achieversit
Contact Us : 8151000080
E-mail : info@achieversit.com
9
Like ,Share
&Save It For Later

More Related Content

Similar to javascript

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)christopherfross
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csMurali G
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Wildan Maulana
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3Usman Mehmood
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
Java script
 Java script Java script
Java scriptbosybosy
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 
ASP.net Manual final.pdf
ASP.net Manual final.pdfASP.net Manual final.pdf
ASP.net Manual final.pdfSwapnilGujar13
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinSimon Gauvin
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handlingsmitha273566
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowPrabhdeep Singh
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 

Similar to javascript (20)

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
DOM Quick Overview
DOM Quick OverviewDOM Quick Overview
DOM Quick Overview
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_cs
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Java script
 Java script Java script
Java script
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
ASP.net Manual final.pdf
ASP.net Manual final.pdfASP.net Manual final.pdf
ASP.net Manual final.pdf
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon Gauvin
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

javascript

  • 1. @Achieversit JavaScript DOM Contact Us : 8151000080 E-mail : info@achieversit.com #Dom 0
  • 2. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 1 Hey Everyone's In this post, you will learn about JavaScript Document Object Model (DOM) with the help of examples. Do Like,save and Share This Post If You Found This Helpful.
  • 3. A Document object represents the HTML document that is displayed in that window. This document enables Javascript to access and manipulate the elements and styles of a website. By the help of document object ,we can add dynamic content to our web page. if you want access any object on your web page you always start with the document. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 2 DOM window.document // OR document
  • 4. The model is built in a tree structure of objects and defines: @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 3 HTML elements as objects. Properties and events of the HTML Methods to access the HTML elements.
  • 5. In this shot, we will learn different ways to select a DOM element in JavaScript. JavaScript provides six methods to select an element from the document. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 4 Select Elements Get element by ID Get elements by class name Get elements by tag name Get elements by name Queryselector Queryselectorall
  • 6. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 5 Get element by ID : The get ElementById() method is used to get a single element by its id. <p id="para">This is my first Paragraph</p> const paragraph = document.getElementById("para1"); console.log(paragraph); //<p id="para">This is my first paragraph </p> Get elements by class name : We can also get more than one object using the getElementsByClassName() method which returns an array.
  • 7. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 6 Get element by tag name : We can also get our elements by tag name using the getElementsByTagName() method. <p class="para">This is my first Paragraph</p> <p class="para">This is my first Paragraph</p> var paras= document.getElementByClassName("para1"); console.log(paras); // HTML Collection(2) // 0: p.para // 1: p:para // length:2 <ul> <li>Coffee</li> <li>Tea</li> </ul> const tagNodes= document.getElementByTagName("li"); console.log(tagNodes); // HTML Collection(li,li) // 0: li // 1: li // length:2
  • 8. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 7 Get Elements By name : The getElementsByName method returns the elements that match the value of the name attribute with the passed string. The return value is a live NodeList Collection. document.getElementByName("first-boy"); It is not recommended to use getElementByName because it works differently on Internet Explorer. Queryselector : The querySelector() method returns the fiirst element that matches a specified CSS selector. That means that you can get elements by id,class,tag and all ot valid CSS selectors.
  • 9. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 8 var header = document.querySelector('#header'); // using id var item = document.querySelector('.list-item'); // using class var heading = document.querySelector('h1'); // using tag var para = document.querySelector('div > p'); // document.querySelector(Css Selectors); Syntax : QueryselectorAll : The querySelectorAll() method is an extension of the querySelector() method. This method returns all the elements that match the passed selector. We can send multiple selectors separated by commas. document.querySelectorAll(".child");//returns all element with child class <div id="parent-1" class="container"> <p>This is my paragraph</p> <span>sp</span> </div> let e = document.querySelectorAll("span, p"); // [p, span]
  • 10. @Achieversit Contact Us : 8151000080 E-mail : info@achieversit.com 9 Like ,Share &Save It For Later