Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. /*
  2. $(document).ready(function(){
  3. $("button").click(function(){
  4. $("shopping-list").toggleClass("li");
  5. });
  6. });
  7.  
  8. $(document).ready(function(){
  9. $("shopping-item-toggle").click(function(){
  10. $(this).li("span").css("text-decoration", "line-through");
  11. });
  12. });
  13.  
  14. $(document).ready(function(){
  15. $("shopping-item-delete").click(function(){
  16. $(this).removeClass("span").css("shopping-item");
  17. });
  18. });
  19. */
  20.  
  21. // target the submit button and
  22. // capture the value then call addItem()
  23.  
  24. $( "#js-shopping-list-form" ).submit(( e ) => {
  25. e.preventDefault();
  26. let val = $('.js-shopping-list-entry').val();
  27. console.log(val);
  28. addItem(val);
  29. });
  30.  
  31.  
  32. // render the new item
  33. function addItem(newItem) {
  34. console.log('success');
  35. $('.shopping-list').append(`
  36. <li>
  37. <span class="shopping-item">${newItem}</span>
  38. <div class="shopping-item-controls">
  39. <button class="shopping-item-toggle">
  40. <span class="button-label">check</span>
  41. </button>
  42. <button class="shopping-item-delete">
  43. <span class="button-label">delete</span>
  44. </button>
  45. </div>
  46. </li>
  47. `);
  48. }
  49.  
  50. $('.shopping-list').on('click', '.shopping-item-toggle', function(e) {
  51. $(this).closest('li').find('.shopping-item').toggleClass('shopping-item__checked');
  52. })
  53.  
  54. $('.shopping-list').on('click', '.shopping-item-delete', function (e) {
  55. $(this).closest('li').remove();
  56. })
Add Comment
Please, Sign In to add comment