
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Tag names of body element's children in JavaScript?
Javascript has provided document.body.children to get the tag names of the children in the body. This method gives out tag names such as p, script, div, etc.
syntax
var t = document.body.children;
Example
In the following example, in the body, there are tags such as 2 paragraph tags and 1 script tag. When the method document.body.children is applied the names of the tags will be displayed as shown in the output.
<html> <body> <p>Gtting the tag names of the body element's children.</p> <p id = "body"></p> <script> var c = document.body.children; var txt = ""; for (var i = 0; i < c.length; i++) { txt = txt + c[i].tagName + "<br>"; document.getElementById("body").innerHTML = txt; } </script> </body> </html>
Output
Gtting the tag names of the body element's children. P P SCRIPT
- Related Questions & Answers
- How to get the body's content of an iframe in JavaScript?
- Array of adjacent element's average - JavaScript
- How to delete all children's elements using Python's Tkinter?
- HTML <body> Tag
- How can I get all element's immediate children with css selectors using selenium?
- How to set the width of an element's border with JavaScript?
- How to set the style of an element's border with JavaScript?
- How to set an element's display type with JavaScript?
- JavaScript's Boolean function?
- Array grouping on the basis of children object’s property in JavaScript
- Dijkstra's algorithm in Javascript
- Prim's algorithm in Javascript
- Kruskal's algorithm in Javascript
- How do I change a tag's inner HTML based on their order in JavaScript?
- JavaScript equivalent of Python's zip function
Advertisements