Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Book Generator</title>
- <script src="https://code.jquery.com/jquery-3.1.0.min.js"
- integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="
- crossorigin="anonymous"></script>
- </head>
- <body>
- <div id="wrapper">
- </div>
- <!--<script src="book-generator.js"></script>-->
- <script>
- window.onload = function () {
- createBook("#wrapper", "Alice in Wonderland", "Lewis Carroll", 1111);
- createBook("#wrapper", "Dune", "Frank Herbert", 2222);
- }
- </script>
- <script>
- let createBook=(function createBook() {
- let id = 1;
- return function (selector, titleName, authorName, isbn) {
- isbn = Number(isbn);
- let div = $('<div>');
- div.attr('id', `book${id}`);
- let title = $('<p>');
- title.addClass('title');
- title.text(titleName);
- let author = $('<p>');
- author.addClass('author');
- author.text(authorName);
- let isbnNumber = $('<p>');
- isbnNumber.addClass('isbn');
- isbnNumber.text(isbn);
- div.append(title);
- div.append(author);
- div.append(isbnNumber);
- $(selector).append(div);
- $(`#book${id}`).append('<button>Select</button>');
- $(`#book${id}`).append('<button>Deselect</button>');
- $('button:contains(Select)').on('click', function () {
- $(this).parent().css('border', '2px solid blue');
- });
- $('button:contains(Deselect)').on('click', function () {
- $(this).parent().css('border', 'none');
- });
- id++;
- };
- })()
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement