Click here to Skip to main content
15,885,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi , i dont want the items to display at same line
Right now it get displayed like this in the browser

XML
<a id="demo">
Text - Saab
<br/>
Text - Volvo
<br/>
Text - BMW
<br/>



And as it it a a href link when hover over the items all get selected but i want if i only select Saab go to that url, and so an. Right not it displays all text values at same linke as it only was 1 link

C#
$(document).ready(function () {
var cars = [
    "Saab",
    "Volvo",
    "BMW"
];

var res = "";

var arrayLength = cars.length;
for (var i = 0; i < arrayLength; i++) {


    res = res + cars[i] + "<br />";



    $("#demo").html(res);
}
});
Posted

1 solution

Try this:
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
  var cars = [
      "Saab",
      "Volvo",
      "BMW"
  ];

  var res = "";

  var arrayLength = cars.length;
  for (var i = 0; i < arrayLength; i++) {
      res = res + "<a href='"+cars[i]+"'>"+cars[i] + "</a><br>";
      $("#demo").html(res);
  }
});
</script>
</head>
<body>
<div id="demo"></div>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900