SlideShare a Scribd company logo
@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

ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
DOM Quick Overview
DOM Quick OverviewDOM Quick Overview
DOM Quick Overview
Signure Technologies
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)
Christopher Ross
 
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 css3
Usman Mehmood
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
borkweb
 
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.pdf
SwapnilGujar13
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
kaven 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 Gauvin
Simon Gauvin
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
SunilChaluvaiah
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
SunilChaluvaiah
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
dtdannen
 
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
smitha273566
 
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
 

Similar to javascript (20)

ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
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
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).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