thelearner
thelearner

Reputation: 1

displaying loops from javascript to html

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

Answers (2)

jmore009
jmore009

Reputation: 12933

You're not targeting .loop correctly. It should be

$(".loop").append(i);

Instead of

$(.loop).append(i);

FIDDLE

Upvotes: 1

Ziga Petek
Ziga Petek

Reputation: 4110

You should use quotes when using a selector in the jQuery function:

   $('.loop').append(i);

Upvotes: 0

Related Questions