Can someone please tell me what wrong with my link function?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Can someone please tell me what wrong with my link function?

Post by Nicole »

function changelink(){
document.getElementById("url").href = arr[new Date().getSeconds()*2-1][0];
document.getElementById("url").appendChild(document.createTextNode(arr[new Date().getSeconds()*2-2][0]));
setTimeout('changelink()',1000);}

Hello, things are sort of working. this function is causing text links I have in an array to stack up, instead of replacing the one from before. Anyone know why? So I am getting a page full of web page links with a new one every second. :lol:

I also can't get it to loop when it gets to the end of the last seconds. These change every second and I have 60 of them in the array, when it gets to the last one it stops. The problem is in the function somewhere everything else is fine. Someone please help me, thank you very much.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Don't you need a removeChild call to go along with your appendChild call?
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Post by Nicole »

Thanks, any idea how?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That would depend on what you need the removal to do. If you want to remove the first child parent.firstChild is the property to give removeChild(); if it's the preceding child, then I believe it's parent.lastChild.
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Post by Nicole »

What do you mean by removal? So that it replaces the link from before and doesn't stack up?
Post Reply