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.
<!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: