0

Currently I have this: http://jsfiddle.net/492cy/

I want to make the span id=textRange in to a hyperlink. Since I have different texts(from the array) populating textRange, I want each Text ("a dude", "a man", "a human") to become different hyperlinks. Thus the end result would be: clicking on "a dude" leads to website1.com, "a man" goes to website2.com, "a human" goes to website3.com

2 Answers 2

1

Not sure what link you're trying to use but this works and will get you going. You can use whatever href's you want but this shows you how to update the href of an <a> element.

jsFiddle Example

function changeText() {
    document.getElementById('textRange').innerHTML=Texts[count];
    document.getElementById('textRange').href = "http://website" + count + '.com';
    count++;
    if (count == Texts.length) { count = '0'; }
    setTimeout(changeText, delay * 1000);
}
Sign up to request clarification or add additional context in comments.

2 Comments

How would I make the links open in another tab (target="_blank")?
Yes, add that attribute to the <a target="_blank"> element. It should open in a new tab, but ultimately, the browser decides that behavior.
0

This is what you want:

var delay = "3"; //how many seconds you wnat the delay to be
var count = '0';
var Texts = ["a dude", "a man", "a human"];
var Links = ["http://www.google.com", "http://www.yahoo.com", "http://www.bing.com"];

function changeText() {
    document.getElementById('textRange').innerHTML = "<a href='" + Links[count] + "'>" + Texts[count] + "</a>";
    count++;
    if (count == Texts.length) {
        count = '0';
    }
    setTimeout("changeText()", delay * 1000);
}

http://jsfiddle.net/492cy/4/

2 Comments

How would I make the links open in another tab (target="_blank")?
That's right. Just add target='blank' before href in the line where the link is constructed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.