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"
[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
$('#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;