krasizorbov

X-mas Gifts

Oct 6th, 2020
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.     let $type = $('#toyType');
  3.     let $price = $('#toyPrice');
  4.     let $description = $('#toyDescription');
  5.     let $button = $('button');
  6.  
  7.     //$button.on('click', function () {
  8.         let type = $type.val();
  9.         let price = $price.val();
  10.         let description = $description.val();
  11.  
  12.         if (type && Number(price) && description) {
  13.             let $div = $('<div>');
  14.             $div.addClass('gift');
  15.  
  16.             let $img = $('<img>');
  17.             $img.attr('src', 'gift.png');
  18.             $div.append($img);
  19.  
  20.             let $h2 = $('<h2>');
  21.             $h2.text(`${type}`);
  22.             $div.append($h2);
  23.  
  24.             let $p = $('<p>');
  25.             $p.text(`${description}`);
  26.             $div.append($p);
  27.  
  28.             let $buyButton = $('<button>');
  29.             $buyButton.text(`Buy it for $${price}`);
  30.             $buyButton.on('click', function (e) {
  31.                 let $divParent = e.target.parentElement;
  32.                 let $sectionParent = $divParent.parentElement;
  33.                 $sectionParent.remove($divParent);
  34.             });
  35.             $div.append($buyButton);
  36.  
  37.             let $section = $('#christmasGiftShop');
  38.             $section.append($div);
  39.         }
  40.  
  41.         $type.val('');
  42.         $price.val('');
  43.         $description.val('');
  44.     //});
  45. }
Advertisement
Add Comment
Please, Sign In to add comment