TheGenie OfTruth TheGenie OfTruth - 3 months ago 7
HTML Question

assigning new properties to an element and retrieving them

So I have some very simple code, but its perplexing me:

<textarea loc="'this is a string'" onclick="console.log(this.loc)"></textarea>


(you can view it here)

My code is supposed to:


  • Give the textarea an attribute of loc ('this is a string')

  • Then, onclick log the loc attribute by accessing itself, then the newly made attribute



This odd glitch is confusing me, and solving this is vital to finishing a program I've been working on. Its so simple, yet so confusing. Any ideas of how to log the textareas location to the console?

Answer

Well, since this question hasn't been closed with an answer I might as well make one with Bergi's knowledge. To get one of an elements attributes simply use:

this.getAttribute("loc")
Comments