Y
Yansky
I'm trying to collect links on a page and then store each link's
textContent and the reference to the link itself in an object, but I'm
not sure how I go about adding new items to the object.
This is what I have so far:
var meh = {};
var getas = document.getElementsByTagName('a');
for(var i=0;i<getas.length;i++){
meh.push({getas.textContent: getas});
}
I know I can't use push() to add to the "meh" object, but that's
basically what I want to do. I'd like to end up with:
meh = { "yahoo" : dom reference to link,
"google" : dom reference to link,
"msn" : dom reference to link };
textContent and the reference to the link itself in an object, but I'm
not sure how I go about adding new items to the object.
This is what I have so far:
var meh = {};
var getas = document.getElementsByTagName('a');
for(var i=0;i<getas.length;i++){
meh.push({getas.textContent: getas});
}
I know I can't use push() to add to the "meh" object, but that's
basically what I want to do. I'd like to end up with:
meh = { "yahoo" : dom reference to link,
"google" : dom reference to link,
"msn" : dom reference to link };