Luca S. Luca S. - 3 months ago 6
HTML Question

How do I put a link inside an array that is displayed through a function

Ok so I have a textbox where, depending on which button you click, text from an array is displayed

var Text= new Array();

Text[1]="a"
Text[2]="b"
Text[3]="c"
function Anzeige(x) {
document.getElementById("Text").innerHTML = Text[x];
}
.......
<input type="button" value="x" onclick="Anzeige(1)">
<input type="button" value="y" onclick="Anzeige(2)">
<input type="button" value="z" onclick="Anzeige(3)">
............
<div id="Anzeigefeld">
<div id="Text"></div>
</div>


So far so good, everything works as planned, but now I want to use a link like "
Text[1]="for more informations look <a style="color:blue;" href="insertlinkhere">here</a>
” and it just stops working (aka nothings happening when I click a button.

Help pls?

Answer

You need to escape occurance of " as \"

Text[1]="for more informations look <a style=\"color:blue;\" href=\"insertlinkhere\">here</a>";
Comments