0

The logic of the code makes sense to me, but there is clearly an error preventing the button from functioning. Am I missing effects in CSS such as hover, and what is the main structural problem with the code that prevents the jquery portion from working. Am meant to use the jquery-ui library for this. Any help would be very much appreciated.


    <link rel="stylesheet" href="style.css" type="text/css">
    <script src="js_lib/jquery-ui.js"></script>

    <title>A Simple Notes List</title>
  

<h1><span>A Simple Notes List</span></h1>

    </div>

<div id="canvas" class="container group">
    
    <div id="primaryContent" class="group">
       <p> </p>

        <form name="checkListForm">
            <input type="text" name="checkListItem"/>
        </form>
        <div id="button">Add!</div>
        <br/>
        <div class="list"></div>

        <p>Click item on list to remove item from list</p>
        
    </div> 
   

<script src="script.js">


// JavaScript Document
$(document).ready(function(){
    $('#button').click(function(){
        var toAdd = $('input[name=checkListItem]').val();
        $('.list').append("<div class='item'>" + toAdd + "</div>");
    });
    
    $('.list').click(function(){
        
    });
});

$(document).on('click', '.item', function(){
    $(this).remove();

});

Update with working code snippet to determine if reopen is required:

"use strict";
// JavaScript Document
$(document).ready(function(){
    $('#button').click(function(){
        var toAdd = $('input[name=checkListItem]').val();
        $('.list').append("<div class='item'>" + toAdd + "</div>");
    });
    
    $('.list').click(function(){
        
    });
});

$(document).on('click', '.item', function(){
    $(this).remove();

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<h1><span>A Simple Notes List</span></h1>

<div id="canvas" class="container group">
    
    <div id="primaryContent" class="group">
       <p> </p>

        <form name="checkListForm">
            <input type="text" name="checkListItem"/>
        </form>
        <div id="button">Add!</div>
        <br/>
        <div class="list"></div>

        <p>Click item on list to remove item from list</p>
        
    </div> 
   
</div>
traktor
  • 17,588
  • 4
  • 32
  • 53
irobot
  • 127
  • 8
  • jQuery is the core library. jQueryUI is built on top of it. If you use jQueryUI, you must also include jQuery. – traktor Feb 01 '21 at 04:02
  • Thank you - this helped my understand the difference between jquery and jquery UI. Still not sure why my code is not working though. – irobot Feb 01 '21 at 04:17
  • The code worked for me after including the jQuery 3.5.1 library. Let me know if you entered a value in the input before clicking the button - if you did I'll post the working code to see if you can find the difference. – traktor Feb 01 '21 at 04:44
  • I see, interesting. I added that library but it still isn't working for me. I did enter a value into the input first before clicking the button...thank you! – irobot Feb 01 '21 at 04:57
  • The question got closed sooner than expected - is it now working? – traktor Feb 01 '21 at 05:27
  • No, still not working :( I don't know why they closed it so soon, or if there is a way to reopen it. Doesn't look like there is – irobot Feb 01 '21 at 05:30
  • Run the code snippet added to the question, enter some text, click the button and after the text appears click the text. This works in Firefox: if you solve the problem you can delete the question or leave it. If not add details of how to reproduce the problem in the question itself. – traktor Feb 01 '21 at 05:48
  • Thank you for the code snippet - unfortunately it doesn't work for me in firefox either. Thank you for your suggestion - I will try asking the question again. Best. – irobot Feb 02 '21 at 06:00
  • There must be a misunderstanding of what is supposed to happen. If you ask again _cut the code down to the **absolute minimum**_ to show the problem, no external files or CSS, one problem to solve only, what you expected, what you got. Best. – traktor Feb 02 '21 at 07:33

0 Answers0