Reputation: 1
I am trying to display the results of a loop into my html from my JS file using Jquery. How do I do it..
here is my html code
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="css/styles.css" rel="stylesheet" type="text/css">
<script src="js/jquery-1.11.2.js"></script>
<script src="js/scripts2.js"></script>
<title>Loops</title>
</head>
<body>
<div class="container">
<h1>Loops </h1>
<div id="results"> Here is your loop!
<p> <span class="loop"></span> </P>
</div>
</div>
</body>
</html>
here is my JS and JQuery code
$(document).ready(function(){
var n = parseInt(prompt("Give me a number from '1':"));
for (var i = 0; i < n; i++) {
$(.loop).append(i);
};
thanks
Upvotes: 0
Views: 57
Reputation: 12933
You're not targeting .loop
correctly. It should be
$(".loop").append(i);
Instead of
$(.loop).append(i);
Upvotes: 1
Reputation: 4110
You should use quotes when using a selector in the jQuery function:
$('.loop').append(i);
Upvotes: 0