0

Trying to add my input onto a list but I keep getting an error. Can anyone please help me? Here is the code:

HTML:

        <div class="add-item">
            <input id="item-add" type='text' placeholder="Enter item to shopping list..." name="itemAdd"></input>
            <button class="add-btn">Add Item</button>
        </div>
        <div class="item-list">
            <H2>Shopping List</H2>
            <ul class="shop-list">
                <li><input type="checkbox">Item 1</li>
                <li><input type="checkbox">Item 2</li>
                <li><input type="checkbox">Item 3</li>
                <li><input type="checkbox">Item 4</li>
                <li><input type="checkbox">Item 5</li>
            </ul>
        </div>  

jQuery:

$(document).ready(function(){
    $(".add-btn").click(function (){
        var x = $('#item-add').val();
        $(".shop-list").append('x');
    });

});
David Trinh
  • 289
  • 1
  • 5
  • 17

2 Answers2

3

You need to include the jQuery library. Add this in the head section.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

Abhishek Sarkar
  • 488
  • 1
  • 4
  • 12
2

You need to include the https:// or http:// part of the URL for a src in the <script> tag. Simply code.jquery.com/jquery.min.js will not find it:

<script src="https://code.jquery.com/jquery.min.js"></script>

Also make sure jQuery is included first, before your code.

Spencer Wieczorek
  • 21,229
  • 7
  • 44
  • 54