PlzSendHelp Posted December 3, 2016 Share Posted December 3, 2016 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 More sharing options...
Ingolme Posted December 3, 2016 Share Posted December 3, 2016 That's not Javascript, it's jQuery. It won't work unless you include a jQuery library. You could also rewrite that as real Javascript instead. Link to comment Share on other sites More sharing options...
PlzSendHelp Posted December 3, 2016 Author Share Posted December 3, 2016 how do i include j query Link to comment Share on other sites More sharing options...
Ingolme Posted December 3, 2016 Share Posted December 3, 2016 There's a page in the tutorial explaining that: http://www.w3schools.com/jquery/jquery_get_started.asp Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now