0

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

2
  • 2
    you are just missing quotes $('.loop').append(i); Commented Jan 13, 2015 at 20:09
  • What specifically goes wrong with the code you've posted? Any errors? Commented Jan 13, 2015 at 20:10

2 Answers 2

1

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

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

Instead of

$(.loop).append(i);

FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.