Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <div class="container">
    <h1>Add Book</h1>
    <form id="book-form">
      <div>
        <label for="title">Title</label>
        <input type="text"  id="title">
      </div>
      <div>
        <label for="author">Author</label>
        <input type="text" id="author" >
        
      </div>
      <div>
        <label for="price">Price</label>
        <input type="text"  id="price">
        <br>
        <br>
        <input type="button" id="btn" value="ADD TO BOOKS">
      </div>
      <div style=" margin-top: 10px;background-color: darkslateblue;">
      <table style="width: 500px; ">
        <thead>
          <tr>
            <th>Title</th>
            <th>Author</th>
            <th>Price</th>
            <th></th>
          </tr>
        </thead>
        <tbody id="book-list"></tbody>
      </table>
    </form>
  </div>
  </div>

</body>
              
            
!

CSS

              
                 body {
   font-size: 14px;
   font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
   background-color: orange;
   text-align: center;
   color: white;
 } 

              
            
!

JS

              
                // Create the two constructors, one for the books and the other one for the ui.
function Book (title, author, price){
 
  this.title = title;
  this.author = author;
  this.price = price;
}

function Ui (){}

  Ui.prototype.addBookToList = function(book){
    let bookList = document.getElementById('book-list');
    let tr = document.createElement('tr');
    tr.innerHTML = `
      <td>${book.title}</td>
      <td>${book.author}</td>
      <td>${book.price}</td>
      <td><a href ='#'>x<a></td>
    `;
    bookList.appendChild(tr);
  }

  Ui.prototype.clearField = function(){

    document.getElementById('title').value = '';
    document.getElementById('author').value = '';
    document.getElementById('price').value = '';
    
  }

// creat an event listener, create the ui variables and call the values
document.getElementById('book-form').addEventListener('submit', function(e){
  const title = document.getElementById('title').value,
        author = document.getElementById('author').value,
        price = document.getElementById('price').value

  // book instantiation
  let book = new Book(title, author, price);
  
  // book instantiation
  let ui = new Ui();

  ui.addBookToList(book);

  ui.clearField();

  e.preventDefault   
});
              
            
!
999px

Console