JQuery Snippets
decayingMind
javascript
3 years ago
955 B
11
Indexable
$( () => {
// JQuery task to new element to select
$("#addBtn").click(function () {
let newBook = $("#book").val();
$("#selectBook").append(new Option(newBook, newBook));
});
// JQuery task to hide/show input text on checkbox
$("#showHide").click(function () {
if ($(this).is(":checked")) {
$("#inputTxt").hide();
} else {
$("#inputTxt").show();
}
});
// Add inputs to table
$("#addBtn").click(function () {
$("#tableRow").clone().appendTo("#table");
});
let books = ["Book1", "Book2", "Book3"];
//Add/Clear Books
$("#addBook").click(function () {
console.log("add btn click");
$.each(books, function (index, book) {
console.log(book);
$("#selectOpt").append(new Option(book, book));
});
});
$("#clearBook").click(function () {
$("#selectOpt > option").each(function (index) {
if ($(this).val() != "Select Book") $(this).remove();
});
});
})Editor is loading...