0

If I have an array how can I create a link of on of the values...www.vermont.gov

This is a part of a switch:

case "b1": // Vermont       

    kf=  new Array("Governor : Peter Shumlin","Size in Square Miles: 9,623","Population: 626,562","Founded: March 4th 1791","www.vermont.gov")

    mb = 'images/vermontst.jpeg';
    mt = 'images/vermontbird.jpg';
    ml = 'images/vermontflower.jpeg';
    tt = "Vermont";

    break;


document.getElementById("title").innerHTML=tt;
document.getElementById("left").style.color=fg;
document.getElementById("left").style.fontSize="30px";
document.getElementById("fac").style.marginLeft="120px";
document.getElementById("fac").style.lineHeight="70px";
document.getElementById("pic").src=mb;
document.getElementById("pict").src=mt;
document.getElementById("picl").src=ml;
document.getElementById("fac").innerHTML = kf.join(" <br/> ");
7
  • 1
    Can you show us how you are displaying the array? Commented Dec 18, 2016 at 18:18
  • 1
    what is displaying the array in your case? Commented Dec 18, 2016 at 18:20
  • It's not clear what you are asking here. What are you trying to do? Commented Dec 18, 2016 at 18:30
  • Sorry I am very new to JS....I need vermont.gov to be an actual link Commented Dec 18, 2016 at 18:31
  • nothing...thnk you Commented Dec 18, 2016 at 18:34

2 Answers 2

1

You can create a <a> tag and then append to it the value of the link from the array using an index.

var a = document.createElement('a');
var linkText = document.createTextNode("my title text");
a.appendChild(linkText);
a.title = "my title text";
a.href = kf[4];
document.body.appendChild(a);
Sign up to request clarification or add additional context in comments.

1 Comment

Probably want to slap a scheme on that kf[4], in the code above it ends up being a relative link, which is almost certainly not right. :-)
0

In this case, the last element of your array could just be something like this:

"<a href='http://www.vermont.gov'>www.vermont.gov</a>"

Comments

Your Answer

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