+ 1
How to create a search text function for a pop up menu
How to create a search text option with js
1 Odpowiedź
0
<input type=search oninput="prgSrh(this)">
<p>MBH</p>
<p>Friend</p>
<p>Somepeople</p>
<p>Idk</p>
<p>JavaScript</p>
<p>ECMAScript</p>
<p>Whatever Script</p>
<script>
function prgSrh(input) {
var prgs = document.getElementsByTagName('p'); // elements
var arrPrgs = [].slice.call(prgs); // array
if(input.value) { // if no input they will be shown
arrPrgs.map(function(ele) { // for each element hidden if there is value
ele.hidden = true;
});
}
arrPrgs.filter(function(ele) {
return ele.textContent.indexOf(input.value) !== -1; // filter the element which it has some content in it from input value
}).map(function(ele) {
ele.hidden = false; // they are not hidden
});
}
</script>
<!-- Just oninput filter the textContent of each element and hide the other -->