Get selected element type
Use the DOM element's tagName
property:
var element_type = field[0].tagName;
Note that browsers are not entirely consistent about the case returned by tagName
, so you should probably call toLowerCase
to be safe: field[0].tagName.toLowerCase()
.
Simple:
var element_type = '<' + field.get(0).tagName.toLowerCase() + '>';
In a nutshell, this retrieves the DOM element associated with field
and gets its tag name via the tagName
attribute inherited from DOMElement
, then transforms the result to lowercase using String
's toLowerCase()
method. Some browsers will return the tagName
in uppercase, so for consistency you should transform it to lower case.