I want to create a search bar that hides all elements until the user actually searches for them, you can check out my JSfiddle for reference: `JSfiddle Link
<div id="search">
<form>
<input type="text" name="search" id="myInput" onkeyup="mFunction()"
placeholder="Search ?..">
</form>
<nav>
<table id="myTable">
<tr class="header">
<th style="width:500px;">Question</th>
</tr>
<tr>
<td onclick="window.location.href='#web'">What is the company email?</td>
</tr>
<tr>
<td onclick="window.location.href='#web'">Is the website currently under
development?</td>
</tr>
<tr>
<td onclick="window.location.href='#game'">Why are the games not working
online?</td>
</tr>
<tr>
<td onclick="window.location.href='#game'">What is the next game or games
that you are working on?</td>
</tr>
<tr>
<td onclick="window.location.href='#game'">Are you working on Modern Jewels
anymore?</td>
</tr>
<tr>
<td onclick="window.location.href='#game'">What are the controls for Modern
Jewels?</td>
</tr>
</table>
</div>
</nav>`
JavaScript/jQuery
function mFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search
query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
I am in need of assistance for a FAQ page where users can search for questions without being overwhelmed by a large list of questions. Any help would be greatly appreciated! :D