Hi,
‘m working on the dropdown menu. However, there is a problem. Search Box only works for the first ul element. Other data is not filtered. For example, D2 cannot be found while searching. No matter how much I researched, I could not find a solution. Waiting for your help. The code I wrote:
“`
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
</head>
<body>
<input type=”text” id=”inputText” onkeyup=”inputFunction()” placeholder=”Search… ” title=”Type in a name”>
<nav class=”menueidown vertical”>
<ul class=”categorydownulortak” id=”inputUl”>
<li data-dropdown>
<a href=”#”>
A
</a>
<div class=”dropdown”>
<ul>
<li data-dropdown>
<a href=”#”>
B
</a>
<div class=”dropdown”>
<ul>
<li>
<a href=”#”>C</a>
</li>
<li data-dropdown>
<a href=”#”>C2</a>
<div class=”dropdown”>
<ul>
<li>
<a href=”#”>D</a>
</li>
<li>
<a href=”#”>D2</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul></div>
</nav>
<script>
function inputFunction() {
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById(“inputText”);
filter = input.value.toUpperCase();
ul = document.getElementById(“inputUl”);
li = ul.getElementsByTagName(“li”);
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”;
}
}
}
</script>
</body>
</html>