SHARE
TWEET

[JS] Add/Delete Items

LusienGG Jun 22nd, 2016 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addItem() {
  2.     let text = $('#newItemText').val()
  3.     addItemsToList(text)
  4.     console.log(text)
  5.     $("#newItemText").val('')
  6. }
  7.  
  8. function addItemsToList(text) {
  9.     let li = $('<li>')
  10.         .append($("<span>").text(text))
  11.         .append(" ")
  12.         .append($("<a href='#' onclick=deleteItem(this)>[Delete]</a>"));
  13.     $('#items').append(li)
  14. }
  15.  
  16. function deleteItem(link){
  17.     $(link).parent().remove();
  18. }
  19.  
  20. $('#newItemText').keypress(function (e) {
  21.     if(e.keyCode == 13){
  22.         $('#newItemText + input[type="button"]').click();
  23.     }
  24. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top