Hello friends, In this article, we will explain to you how to get html tag in javascript. we will give you a simple example of how to get the tag name in javascript.
Example
in this example, we get the tag name using the getElementById. so you can see the below example.
<!DOCTYPE html> <html lang="en"> <head> <title>how to get html tag in javascript - xpertphp</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <h2>how to get html tag in javascript</h2> <div id="container"> Hello World! </div> <br> <button type="button" onclick="clickMe()">Click Me</button> <script> function clickMe(){ var element = document.getElementById('container'); var tag = element.tagName; alert(tag); } </script> </body> </html>
Please follow and like us: