I am trying to access the data which I am storing in <meta> tags using javascript, but for some reason the getAttribute() function is not working.
document.write("<p>")
document.write("Hello, world")
document.write("</p>")
var metatags = document.getElementsByTagName('meta[id="candidate1"]');
metatags.getAttribute("data-candidate")
document.write(metatags)
Here is my code:
<body>
<h1>Testing 1, 2</h1>
<meta id="candidate1" data-candidate="1">
<meta id="candidate2" data-candidate="2">
</body>
The error produced is "Uncaught TypeError: metatags.getAttribute is not a function"
Does anyone know why this is not working or if there is a better way of accessing the data stored in the tag?
I am a complete novice to javascript so appreciate any tips you can give me.