search divs by name

Solutions on MaxInterview for search divs by name by the best coders in the world

showing results for - "search divs by name"
Cloé
16 Nov 2019
1document.getElementById('search').addEventListener('keyup', search);
2function search() {
3        var input = document.getElementById("search input");
4        var filter = input.value.toLowerCase();
5        var nodes = document.getElementsByClassName('target div');
6      
7        for (i = 0; i < nodes.length; i++) {
8          if (nodes[i].innerText.toLowerCase().includes(filter)) {
9            nodes[i].style.display = "block";
10          } else {
11            nodes[i].style.display = "none";
12          }
13        }
14}
15//All divs need to have the same class