mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 14:20:41 +01:00
33 lines
No EOL
881 B
JavaScript
33 lines
No EOL
881 B
JavaScript
$(document).ready(function () {
|
|
$("#search-recipes").on("keyup", searchRecipe);
|
|
$("#clear-search-string").click(clearSearchString);
|
|
});
|
|
|
|
function searchRecipe() {
|
|
var searchString = $("#search-recipes").val().toUpperCase();
|
|
var recipes = $("#recipes a");
|
|
|
|
for (var i = 0; i < recipes.length; i++) {
|
|
if (recipes[i].innerHTML.toUpperCase().indexOf(searchString) > -1) {
|
|
$(recipes[i]).show()
|
|
}
|
|
else {
|
|
$(recipes[i]).hide();
|
|
}
|
|
}
|
|
|
|
$("#recipes").children().each(index => {
|
|
var container = ($("#recipes").children())[index];
|
|
$(container).removeClass("d-none").addClass("d-flex");
|
|
if(($(container).find("a:visible")).length==0){
|
|
$(container).removeClass("d-flex").addClass("d-none");
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
function clearSearchString() {
|
|
$("#search-recipes").val("");
|
|
$("#search-recipes").focus();
|
|
$("#search-recipes").keyup();
|
|
} |