PDA

View Full Version : Display HTML in Javascript



locbtran
05-21-2012, 09:40 PM
I'm trying to display the elements in an array but doesn't seem to work:


var myurl=new Array("google.com", "yahoo.com");

for (i=0;i<=myurl.length-1;i++){
document.writeln("<a href='http://www.' + myurl[i] + target='_blank'>");
}


Not sure why it is not working??

keyboard
05-22-2012, 12:13 AM
<script type="text/javascript">
var myurl=new Array("google.com", "yahoo.com");

for (i=0;i<=myurl.length-1;i++){
document.writeln("<a href='http://www." + myurl[i] + "' target='_blank'>Link</a>");
}
</script>

ApacheTech
05-22-2012, 12:56 AM
<head>
<script type="text/javascript">
var myurl=new Array("google.com", "yahoo.com");

var el = document.getElementById( 'urlDiv' );

for (i=0;i<=myurl.length-1;i++){
el.innerHTML += "<p><a href='http://www." + myurl[i] + "' target='_blank'>Link</a></p>";
}
</script>
</head>

<body>
<div id="urlDiv"></div>
</body>