Home > Web Front-end > JS Tutorial > body text

How to get element tags in jquery

王林
Release: 2020-11-19 16:52:57
Original
4181 people have browsed it

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);].

How to get element tags in jquery

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>
Copy after login

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);
Copy after login

The output results are: p

Method 2:

var  name = $("#p").prop("tagName");
alert(name);
Copy after login

The result: p

Method three:

My own encapsulated method

var  name = $("#p").prop("nodeName");
alert(name);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!