Home  >  Article  >  Web Front-end  >  Code to get tag name based on jQuery_jquery

Code to get tag name based on jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 17:51:441277browse

How to get the name of an element with jquery, such as

dd

$("#aa").xxxmethod Yesterday, how to get "div"

with jquery The name of an element such as
dd

$("#aa").xxxmethod gets "div"

BN1GWSS}8EVZ0_~EW6UFQ
[Kunming] Si Xue. Chuan Qiong (447031499) 13:35:50
$('#elementId').get(0).tagName
$("#aa")[0] .tagName This is enough

jQuery to get the tag name

Copy code The code is as follows:

$('#elementId').get(0).tagName

Here you get the tag name in capital letters, such as: A, DIV

Background knowledge:

Conversion between jQuery objects and dom objects
Only jquery objects can use the methods defined by jquery. Note that there is a difference between dom objects and jquery objects. When calling methods, you should pay attention to whether you are operating on dom objects or jquery objects.
Ordinary dom objects can generally be converted into jquery objects through $().
For example: $(document.getElementById("msg")) is a jquery object, and you can use jquery methods.
Because the jquery object itself is a collection. Therefore, if the jquery object is to be converted into a dom object, one of the items must be retrieved, which can generally be retrieved through an index.
For example: $("#msg")[0], $("div").eq(1)[0], $("div").get()[1], $("td" )[5] These are dom objects, you can use methods in dom, but you can no longer use Jquery methods.
The following writing methods are correct:
$("#msg").html();
$("#msg")[0].innerHTML;
$("# msg").eq(0)[0].innerHTML;
$("#msg").get(0).innerHTML;
Statement:
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