How to get the tag name in jQuery
Hello friends, In this article, we will explain to you how to get the tag name in jQuery. we will give you a simple example of how to get html tag name in jquery.
Example
in this example, we get the tag name using the get(0).tagName function. so you can see the below example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <!DOCTYPE html> <html lang="en"> <head> <title>How to get the tag name in jQuery - XpertPhp</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ var tag1 = $('#container')[0].tagName; var tag2 = $('#container').get(0).tagName; alert(tag1);//DIV alert(tag2);//DIV }); }); </script> </head> <body> <h2>How to get the tag name in jQuery</h2> <div id="container"> Hello World! </div> <br> <button type="button">Click Me</button> </body> </html> |
Please follow and like us: