I have a working filtered list using JS, but the amount of list elements is growing. So I need to divide the list in pages, but for the filter to keep working for the whole list, even if the list element is not showing because it is in another page.
I've seen how to make a "previous" and "next" buttons for list, but it breaks down the filter js, because it consists basically of placing the contents on different divs, but the filter will only filter the first one.
This is my HTML now:
<section>
<input type="text" id="barraBusqueda" onkeyup="buscar()" placeholder="Buscar artÃculos">
<ul id="articulos">
<li><a href="/es/blog/1.html">Article 1</a></li>
<li><a href="/es/blog/2.html">Article 2</a></li>
<li><a href="/es/blog/3.html">Article 3</a></li>
<li><a href="/es/blog/4.html">Article 4</a></li>
<li><a href="/es/blog/5.html">Article 5</a></li>
<li><a href="/es/blog/6.html">Article 6</a></li>
<li><a href="/es/blog/7.html">Article 7</a></li>
<li><a href="/es/blog/8.html">Article 8</a></li>
<li><a href="/es/blog/9.html">Article 9</a></li>
<li><a href="/es/blog/10.html">Article 10</a></li>
</ul>
</section>
And my JS:
function buscar() {
// Declare variables
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("barraBusqueda");
filter = input.value.toUpperCase();
ul = document.getElementById("articulos");
li = ul.getElementsByTagName("li");
// Loop through all list items, and hide those who don't match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
It works fine, but all the elements have to be showing, and I don't want an eternal scroll through dozens of list items.
Goal would be that the browser only displays 5 list items at a time, with a next and previous button to navigate through them, but that the filter considers all the list items, even those that are in other pages.