如何获取在其中创建的javascript元素的名称



我正在制作一个像reactJS这样的javascript库。而且,我被一个问题卡住了。

//how to get the name of an element created in javascript in another function without parameter
//Example
let demo = document.createElement("div"):
function example(element){
// this will get the name of the element ,ie.., div
console.log(...)
//should print "div" on the console
}
example(demo);

有人能帮我吗?Edit: This is just an example. The libray is more complex and long that I cant add it here.

尝试获取元素。localName,元素。nodeName或element.tagName:

function example(element){
console.log(element.localName); // should print 'div'
console.log(element.nodeName); // should print 'DIV'
console.log(element.tagName); // should print 'DIV'
}

最新更新