I got a problem here. The search is working almost. But when I am deleting something it doesnt appear again. (tried something like else {names[i].parentElement.style.display = "block"}). This didnt work.
And maybe someone could tell me what to do if someone hits enter and everthing gets resetted. Thanks to every answer.
function searchFunction() {
const search = document.getElementById("myinput").value;
const names = document.getElementsByClassName("names");
console.log(search)
for (var i = 0; i < names.length; i++) {
if (names[i].innerHTML.toUpperCase().includes(search.toUpperCase()) == false) {
names[i].parentElement.style.display = "none"
}
}
}
Nothing reappears because you only hide stuff using
Comment posted by Maximilian Rabe
Thank thought is was wrong when i tried it because I got a grid for the rows. And i needed to set in to display “flex” or “none”. But thanks for your help.
Comment posted by Lain
Setting back the display to an empty string is usually better. Like this you overwrite any css definition the user could have set somewhere.
Comment posted by Jamiec
@Lain I totally get (and agree with) your point, but setting it back to blank would
Comment posted by Lain
It would not overwrite css definitions atleast, merely inline styles.