I attempted to implement an image filter for my website by using the code below:
<script>
function myFunction() {
// Initialize variables
var input, filter, ul, li, a, i;
input = document.getElementById('myInput');
filter = input.value.toUpperCase();
ul = document.getElementById("searchColumns");
li = ul.getElementsByTagName('figure');
if (filter==""){
li[i].style.display = "none";
}
else{
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("figcaption")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "inline-block";
} else {
li[i].style.display = "none";
}
} }
}
</script>
However, the issue I encountered is that all of the 200+ images are loading on startup, resulting in a delay. Is there a method to prevent them from loading until they are filtered?