Element.nodeName not defined for html element created using jQuery

I created a new HTML element using jQuery.

var v=jQuery('<p>Hello</p>); 

But when I try to get the nodeName of a new element,

 v.nodeName.toLowerCase(); 

I get an error saying nodeName is undefined. What is wrong here?

Thanks.

+4
source share
1 answer

v is a jQuery object containing a dom element, not a real dom element, you should do:

 v[0].nodeName.toLowerCase(); 
+7
source

Source: https://habr.com/ru/post/1310826/


All Articles