how to apply filter option for following html code that will check and display on real time input given.
<div class="block-parent">
<input type="text" name="search" class="search">
<div class="answer block1" style="color: white; background-color: rgb(98, 128, 145);">Nick</div>
<div class="answer block1" style="color: black; background-color: rgb(114, 139, 137);">Sam</div>
<div class="answer block1" style="color: white; background-color: rgb(123, 138, 115);">John</div>
</div>
Example: When user type nick on search box then only <div class="answer block1" style="color: white; background-color: rgb(98, 128, 145);">Nick</div>
is need to show & other two div is need to hide .Please anyone can suggest a good method .
ie creating a search result like https://docs.angularjs.org/api/ng/filter/filter
I added with
oninput
event Its will check and display on real time input given. Case sensitive also.At the time string empty.It wont display anything.Its will search the each letter of containing in resultUpdate the answer with
Case sensitive select : see the reference
You can check for the div's content using contains and hide/show them respectively
Hope this helps
Building on top of Geeky's code, you could just do a case insensitive : contains selector that can do case insensitive check.
Try this:
This will search even when case-insensitive
give id to all the div's then try this
then in click event of nick write below code
You can use the jQuery
change()
method and check the input value, then show or hide the appropriate divs.