Reputation: 1423
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
Upvotes: 0
Views: 77
Reputation: 308
ID change is the only thing you need to do:
$('#myTable').append(content);
Upvotes: 0
Reputation: 2016
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>
Upvotes: 2
Reputation: 133403
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);
Upvotes: 2