0

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!

Community
  • 1
  • 1

1 Answers1

0

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

Xotic750
  • 22,914
  • 8
  • 57
  • 79
  • {title}
    HOME ~~Paste here~~ ASK
    ^ @Xotic750 - thank you! Should this work if I paste the entirety as such? (Ignorant question, apologies)
    –  Apr 24 '13 at 18:50
  • That depends on where you paste it. – Xotic750 Apr 24 '13 at 19:12
  • You can not paste the code from the example above directly (unmodified) into a .html document, serve it from a server and expect a browser to interpret it. You must construct the html document appropriately and also enclose the javascript within script tags. Read a tutorial or two, you can find one at the following: http://www.w3schools.com/html/ – Xotic750 Apr 24 '13 at 19:25
  • Of course, @Xotic750, just one query - can I set the jsfiddle link you gave as a source in style sheet terms? –  Apr 26 '13 at 17:19
  • Not programatically as in includeable javascript, but sure as a link, use it as you will. – Xotic750 Apr 26 '13 at 17:22