Study Portal Logo Infokept Career Hub

Group 3: Library Book Manager

Updated: 30 Jul 2026, 08:58:35

Library Book Manager

Project Structure

 
Library-Book-Manager/
│
├── index.html
├── style.css
├── script.js
├── library.js
├── books.json
└── README.txt
 

Features Included

  • 📚 Add new books
  • 🔍 Search books by title or author
  • 🔄 Toggle book status (Available ↔ Issued)
  • 🗑️ Delete books
  • 💾 Local Storage support
  • 📄 Sample data in books.json
  • 🎨 Simple responsive interface

File 1: index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Library Book Manager</title>

    <link rel="stylesheet" href="style.css">
</head>

<body>

    <div class="container">

        <header>
            <h1>📚 Library Book Manager</h1>
        </header>

        <!-- Add Book Form -->
        <section class="form-section">

            <form id="f">

                <input
                    type="text"
                    id="title"
                    placeholder="Book Title"
                    required>

                <input
                    type="text"
                    id="author"
                    placeholder="Author Name"
                    required>

                <button type="submit">
                    Add Book
                </button>

            </form>

        </section>

        <!-- Search -->
        <section class="search-section">

            <input
                type="text"
                id="q"
                placeholder="Search by Title or Author">

        </section>

        <!-- Books Table -->
        <section class="table-section">

            <table>

                <thead>

                    <tr>

                        <th>Title</th>

                        <th>Author</th>

                        <th>Status</th>

                        <th>Action</th>

                    </tr>

                </thead>

                <tbody id="tb">

                </tbody>

            </table>

        </section>

    </div>

    <script src="library.js"></script>
    <script src="script.js"></script>

</body>

</html>


 File 2: style.css

body {
    font-family: Arial, sans-serif;
    max-width: 900px;
    margin: auto;
    padding: 20px;
}

input,
button {
    padding: 8px;
    margin: 5px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border: 1px solid #ccc;
    padding: 8px;
}

 

File 3: script.js File

/*=========================================
    Library Book Manager
    script.js
=========================================*/

let books = [];

// DOM Elements
const f = document.getElementById("f");
const tb = document.getElementById("tb");
const q = document.getElementById("q");

/*=========================================
    Load Books
=========================================*/
async function init() {

    books = loadLS();

    if (!books) {

        const response = await fetch("books.json");

        books = await response.json();

    }

    render();

}

/*=========================================
    Display Books
=========================================*/
function render(arr = books) {

    tb.innerHTML = "";

    arr.forEach((book, index) => {

        tb.innerHTML += `

        <tr>

            <td>${book.title}</td>

            <td>${book.author}</td>

            <td>
                ${book.issued ? "Issued" : "Available"}
            </td>

            <td>

                <button onclick="toggle(${index})">
                    Toggle
                </button>

                <button onclick="delb(${index})">
                    Delete
                </button>

            </td>

        </tr>

        `;

    });

}

/*=========================================
    Add New Book
=========================================*/
f.onsubmit = function (e) {

    e.preventDefault();

    books.push({

        title: title.value,

        author: author.value,

        issued: false

    });

    saveLS(books);

    render();

    f.reset();

};

/*=========================================
    Search Books
=========================================*/
q.oninput = function () {

    const keyword = q.value.toLowerCase();

    const filteredBooks = books.filter(book =>

        book.title.toLowerCase().includes(keyword) ||

        book.author.toLowerCase().includes(keyword)

    );

    render(filteredBooks);

};

/*=========================================
    Toggle Book Status
=========================================*/
function toggle(index) {

    books[index].issued = !books[index].issued;

    saveLS(books);

    render();

}

/*=========================================
    Delete Book
=========================================*/
function delb(index) {

    books.splice(index, 1);

    saveLS(books);

    render();

}

/*=========================================
    Start Application
=========================================*/
init();

 

4: library.js File

/* ===========================================
   Local Storage Helper Functions
   =========================================== */

/**
 * Load books from Local Storage.
 * Returns the saved array of books.
 * Returns null if no data exists.
 */
function loadLS() {

    return JSON.parse(
        localStorage.getItem("books") || "null"
    );

}

/**
 * Save books array to Local Storage.
 * @param {Array} books
 */
function saveLS(books) {

    localStorage.setItem(
        "books",
        JSON.stringify(books)
    );

}

 

5: books.json File

[
    {
        "title": "Clean Code",
        "author": "Robert C. Martin",
        "issued": false
    },
    {
        "title": "Eloquent JavaScript",
        "author": "Marijn Haverbeke",
        "issued": true
    }
]

 

6: README.txt

Mini Library Book Manager. Run with Live Server.

About Author

Swarnim Raj - Author Infokept Career Hub

Swarnim Raj

Author & Career Content Writer

Experienced education and career writer at Infokept Career Hub, creating simple, research-based guides for students and government job aspirants.

Search Related Topics