Incorporating into a line the periodic changing of text

Question!

I've not had much luck trying to incorporate this idea/solution/feature into a link such as:

<a href="/" title="index">HOME</a>    

The text HOME would be able to switch between various other words, in an ideal world..

Any advice would be appreciated.

Thanks!



Answers
This is a possible solution

<a id="link" href="#" title="home">HOME</a>  

var array = [];

array.push("home");
array.push("away");
array.push("there");
array.push("there");
array.push("back");
array.push("moon");
array.push("stars");

var link = document.getElementById("link");
var index = 0;
var length = array.length;
var period = 1000; // miliseconds
var id;

function changeLink() {
    index += 1;
    if (index >= length) {
        index = 0;
    }

    link.textContent = array[index].toUpperCase();
    link.title = array[index];
}

id = setInterval(changeLink, period);

on jsfiddle

By : Xotic750


This video can help you solving your question :)
By: admin