I need a way to determine the type of an HTML element in JavaScript. It has the ID, but the element itself could be a <div>, a <form> field, a <fieldset>, etc. How can I achieve this?
I need a way to determine the type of an HTML element in JavaScript.
Share
nodeNameis the attribute you are looking for. For example:Note that
nodeNamereturns the element name capitalized and without the angle brackets, which means that if you want to check if an element is an<div>element you could do it as follows:While this would not give you the expected results: