Home > Article > Web Front-end > How to get element tags in jquery
Jquery method of getting element tags: You can get element tags by using the tagName attribute, such as [var name = $("#p").get(0).tagName; alert(name);].

html code is as follows:
(Learning video sharing: jquery video tutorial)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../js/jquery-3.2.1.js"></script>
</head>
<body>
<p id ="p" >这是p标签</p>
<script>
</script>
</body>
</html>The method is as follows:
Method 1: Use the tagName attribute to implement
var name = $("#p").get(0).tagName;
alert(name);
var name = $("#p")[0].tagName;
alert(name);The output results are: p
Method 2:
var name = $("#p").prop("tagName");
alert(name);The result: p
Method three:
My own encapsulated method
var name = $("#p").prop("nodeName");
alert(name);Result: p
Related recommendations: js tutorial
The above is the detailed content of How to get element tags in jquery. For more information, please follow other related articles on the PHP Chinese website!