Advertisement
kema

Book Generator

Oct 22nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function createBook() {
  2.     let id=1;
  3.     return function (selector, title, author, isbn) {
  4.  
  5.         let fragment = document.createDocumentFragment();
  6.         let container = $(selector);
  7.  
  8.         let bookContainer = $("<div>");
  9.         let titleParagraph = $("<p>");
  10.         let authorParagraph = $("<p>");
  11.         let isbnParagraph = $("<p>");
  12.         let selectBtn = $("<button>Select</button>");
  13.         let deselectBtn = $("<button>Deselect</button>");
  14.  
  15.         titleParagraph.text(title);
  16.         authorParagraph.text(author);
  17.         isbnParagraph.text(isbn);
  18.  
  19.         bookContainer.attr('id', 'book' + id);
  20.         id++;
  21.         titleParagraph.addClass('title');
  22.         authorParagraph.attr('class', 'author');
  23.         isbnParagraph.addClass('isbn');
  24.  
  25.         selectBtn.on('click', function () {
  26.             bookContainer.css('border', '2px solid blue');
  27.         });
  28.         deselectBtn.on('click', function () {
  29.             bookContainer.css('border', 'none');
  30.         });
  31.  
  32.         bookContainer.append(titleParagraph).append(authorParagraph).append(isbnParagraph).append(selectBtn).append(deselectBtn);
  33.  
  34.         bookContainer.appendTo(fragment);
  35.         container.append(fragment);
  36.     }
  37. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement