0

Below is my HTML fine. I am getting a blank page as output

<html>
<head>
<script src="jquery-1.11.0.min.js">
</script>
<script>
var content = "<table>"
for(i=0; i<10; i++){
content += '<tr><td>' + 'answer' +  i + '</td></tr>';
}
content += "</table>"
$('#myTable').append(content);

</script>
</head>
<body>
<div id="myTable"></div>
</body>
</html>

the output that i expect is answer 1 answer 2 ....... answer 3

Count
  • 1,395
  • 2
  • 19
  • 40

3 Answers3

2

Wrap your code in document-ready handler. it specify a function to execute when the DOM is fully loaded. like

$(document).ready(function() {
  //Your code
});

You should read When should I use jQuery's document.ready function?

Also you are using incorect id. use

$('#myTable').append(content);

instead of

$('#here_table').append(content);

DEMO

Community
  • 1
  • 1
Satpal
  • 132,252
  • 13
  • 159
  • 168
2

Your js isn't waiting for the document to load, and missing 2 semi-colons.

Try changing your js to:

<script>
$(document).ready(function(){ 
  var content = "<table>";
  for(i=0; i<10; i++){
    content += '<tr><td>' + 'answer' +  i + '</td></tr>';
  }
  content += "</table>";
  $('#here_table').append(content);
}); 
</script>
flauntster
  • 2,008
  • 13
  • 20
0

ID change is the only thing you need to do:

$('#myTable').append(content);
Aniruddha
  • 308
  • 2
  • 11