0

How to get selected element tag name using jQuery?

Use .prop("tagName") function.

console.log($('div').prop('tagName')); // DIV
console.log($('p').prop('tagName')); // P
console.log($('span').prop('tagName')); // SPAN

console.log($('<myTag/>').prop('tagName')); // MYTAG
<div>
  div element
</div>

<p>
  p element
</p>

<span>
	span element
</span>
RUN
add comment
Suggest a different solution or add another example