HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs 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 its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Online Library</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#"
>Home <span class="sr-only">(current)</span></a
>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input
class="form-control mr-sm-2"
type="search"
placeholder="Search"
aria-label="Search"
/>
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">
Search
</button>
</form>
</div>
</nav>
<div id="alertuser"></div>
<div class="container my-3">
<h1>Welcome to My Library</h1>
<hr />
<form id="mylibraryform">
<div class="form-group">
<label for="exampleInputEmail1">User Name</label>
<input
type="text"
class="form-control"
id="User-Name"
aria-describedby="emailHelp"
/>
<small id="emailHelp" class="form-text text-muted"
>We'll never share your user name with anyone else.</small
>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Book Name</label>
<input type="text" class="form-control" id="Book-Name" />
</div>
<div class="form-group">
<label for="bookType">Book Type</label>
<div class="check-boxes my-3 mx-5">
<div class="form-check p-2">
<input
class="form-check-input"
type="radio"
name="check-box"
id="Fiction"
value="Fiction"
/>
<label class="form-check-label" for="Fiction"> Fiction </label>
</div>
<div class="form-check p-2">
<input
class="form-check-input"
type="radio"
name="check-box"
id="Programing"
value="Programing"
/>
<label class="form-check-label" for="Programing">
Programing
</label>
</div>
<div class="form-check p-2">
<input
class="form-check-input"
type="radio"
name="check-box"
id="Cooking"
value="Cooking"
/>
<label class="form-check-label" for="Cooking"> Cooking </label>
</div>
</div>
</div>
<button type="submit" class="btn btn-outline-dark">Add Book</button>
</form>
<table class="table table-dark my-3">
<thead>
<tr>
<th scope="col">Sl No.</th>
<th scope="col">Date of issue</th>
<th scope="col">Reader</th>
<th scope="col">Book Name</th>
<th scope="col">Genre</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="table-body"></tbody>
</table>
</div>
// getting input from input areas -->
function inputs(userName, bookName, type) {
this.userName = userName;
this.bookName = bookName;
this.type = type;
}
class Display {
constructor() {}
add(arrayInputs) {
let tableBody = document.getElementById("table-body");
let today = new Date().toLocaleDateString();
let htmltobeadded = "";
for (let i = 0; i < arrayInputs.length; i++) {
htmltobeadded += `
<tr>
<td>${i + 1}</td>
<td>${today}</td>
<td>${arrayInputs[i].userName}</td>
<td>${arrayInputs[i].bookName}</td>
<td>${arrayInputs[i].type}</td>
<td> <button type="button" onclick = "deleteItem(${i})" class ="dlt-btn btn-primary btn " id ="dlt-btn"> Delete </button> </td>
</tr>
`;
}
tableBody.innerHTML = htmltobeadded;
}
clear() {
let myForm = document.getElementById("mylibraryform");
myForm.reset();
}
validate(inputs) {
if (inputs.userName == "" || inputs.bookName == "") {
return false;
} else return true;
}
alertuser(type, sub, massage) {
let alertuser = document.getElementById("alertuser");
let htmltobeaddedinalert = ` <div class="alert alert-${type} alert-dismissible fade show" id="alert" role="alert" >
<strong>${sub}</strong> ${massage}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>`;
alertuser.innerHTML += htmltobeaddedinalert;
setTimeout(() => {
alertuser.innerHTML = "";
}, 4000);
}
// check if the book is issued or not -->
checkIssue(listArray, o1) {
for (let i = 0; i < listArray.length; i++) {
if (listArray[i].bookName == o1.bookName) {
this.issuedUser = listArray[i].userName;
return 0;
}
}
return 1;
}
}
// Show BookList even after reload -->
function showList() {
let listItems = localStorage.getItem("listItems");
if (listItems == null) {
listArray = [];
} else {
listArray = JSON.parse(listItems);
}
new Display().add(listArray);
// console.log(listArray);
}
showList();
// Deleting List Item -->
function deleteItem(index) {
let listItems = localStorage.getItem("listItems");
if (listItems == null) {
listArray = [];
} else {
listArray = JSON.parse(listItems);
}
listArray.splice(index, 1);
localStorage.setItem("listItems", JSON.stringify(listArray));
showList();
}
// add submit finction to the form -->
const form = document.getElementById("mylibraryform");
form.addEventListener("submit", formSubmit);
function formSubmit(e) {
e.preventDefault();
let givenUserName = document.getElementById("User-Name").value;
let givenBookName = document.getElementById("Book-Name").value;
let givenType;
let checkFiction = document.getElementById("Fiction");
let checkPrograming = document.getElementById("Programing");
let checkcooking = document.getElementById("Cooking");
if (checkFiction.checked) {
givenType = checkFiction.value;
} else if (checkPrograming.checked) {
givenType = checkPrograming.value;
} else {
givenType = checkcooking.value;
}
let o1 = new inputs(givenUserName, givenBookName, givenType);
let displayObj = new Display();
if (displayObj.validate(o1) && displayObj.checkIssue(listArray, o1) == 1) {
let listItems = localStorage.getItem("listItems");
if (listItems == null) {
listArray = [];
} else {
listArray = JSON.parse(listItems);
}
listArray.push(o1);
localStorage.setItem("listItems", JSON.stringify(listArray));
// console.log(listArray.length);
new Display().add(listArray);
displayObj.clear();
displayObj.alertuser("success", "Success", "Book is issued");
} else if (displayObj.checkIssue(listArray, o1) == 0) {
let issuedUser =
displayObj.alertuser(
"danger",
"Oops!",
`Book is already issued by ${displayObj.issuedUser}`
);
displayObj.clear();
} else {
displayObj.alertuser("danger", "Oops!", "Book is not issued");
displayObj.clear();
}
}
Also see: Tab Triggers