Mock Mark up:
<div class="post">
<a name="1234"></a>
</div>
Remember this is mock markup of course there is more html in the above, this a is the first a tag inside the parent .post
Here is my code:
var pid = [];
var post = document.getElementsByClassName('post');
for(var i=0;i<post.length;i++){
var postId = post[i].getElementsByTagName('a')[0].getAttributeNode('name');
pid.push(postId);
}
alert(pid);
I keep getting literally ,,,,,,
I have tried .getAttribute and .getAttributeNode
Is there something I am doing wrong here? I am trying to make an array of "names" persay to classify these later on using an ID specification.
Any suggestions thank you!
,,,,,,"? That's thealertcontent? Tryconsole.log(), it usually yields clearer info about the variable. What was the difference between the results from.getAttributeand.getAttributeNode?getAttribute: jsfiddle.net/pQE2X/1