Advertisement
gadjov

Untitled

Oct 26th, 2016
301
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 container = $(selector);
  6.         let fragment = document.createDocumentFragment();
  7.  
  8.         let div = $("<div>");
  9.         let pTitle = $("<p>");
  10.         let pAuthor = $("<p>");
  11.         let pIsbn = $("<p>");
  12.         let selectBtn = $("<button>Select</button>");
  13.         let deselectBtn = $("<button>Deselect</button>");
  14.  
  15.         div.attr("id", "book" + id);
  16.         id++;
  17.         pTitle.addClass("title");
  18.         pAuthor.addClass("author");
  19.         pIsbn.addClass("isbn");
  20.  
  21.         pTitle.append(title);
  22.         pAuthor.append(author);
  23.         pIsbn.append(ISBN);
  24.  
  25.  
  26.         pTitle.appendTo(div);
  27.         pAuthor.appendTo(div);
  28.         pIsbn.appendTo(div);
  29.         selectBtn.appendTo(div);
  30.         deselectBtn.appendTo(div);
  31.         div.appendTo(fragment);
  32.  
  33.         container.append(fragment);
  34.        
  35.         selectBtn.on("click", function () {
  36.             div.css("border", "solid blue 2px")
  37.         });
  38.  
  39.         deselectBtn.on("click", function () {
  40.             div.css("border", "none");
  41.         });
  42.     }
  43. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement