Jump to content

PLZ Help! i don't know why its not working


PlzSendHelp
 Share

Recommended Posts

i wanted to use this sample code from code pen http://codepen.io/emilioincerto/pen/yaVzJd

 

However, when i want to use it my java script isn't working

 

Here is my code.

<!DOCTYPE html>
<html>
<head>

<script src="../java/java2.js"></script>
	<title>
		

	</title>
</head>
<body>
<h1>Shopping List</h1>
<ul class="shopping-list">
</ul>

<div>
  <input type="text" id="item" />
  <button id="b1" value="Add">Add</button>
</div>


</body>
</html>
************This is JavaScript***********



$(document).ready(
  function(){
    
    $("#b1").on("click", function(){
      //grab the value of input element with id item and set it to userinput
      var userInput = $("#item").val();
      //log userinput to the console
      console.log( userInput );
      
      var shoppingItem = $(document.createElement("li"));
      //shoppingItem.addClass("item");
      shoppingItem.html(userInput);
      
      if (userInput.length > 3){
        $("ul.shopping-list").append(shoppingItem);
        //clear all input fields
        $("input").val("");
      }
      
    });
    
   $("ul").on("click", "li", function(){
      console.log("test number two");  
     $(this).remove();
   });
    
  }
);
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...