Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name attribute of a span element

I have an span tag in my document. I'd like to access it's name property, but it doesn't seem to be there. According to MDN Element Name the name property doesn't apply to a span.

That being said the document.getElementsByName returns my span by name.

like image 245
Eric Avatar asked Dec 25 '22 15:12

Eric


1 Answers

Assuming you already have a reference to your span handy, just use Element.getAttribute().

console.log(mySpan.getAttribute('name')); 
like image 72
Luke Avatar answered Dec 27 '22 04:12

Luke