I have an image gallery with title to every image and a input field with search button . when i click the search button i want the images that contain specific character to be displayed and the rest to be hidden and when the input field is empty all the images to be displayed again .
Like if i type "c" all the images with title "TitleCat" to be left and rest hidden. If i type "title" all the images should be still displayed.
<button id="search" onclick="sortImage()" type="button">
<input type="text" id="inputValue" placeholder="Type to search">
</input>SEARCH
</button>
<div id="Images">
<div id="img">
<img src"....">
<p>TitleCat</p>
</div>
<div id="img">
<img src"....">
<p>TitleDog</p>
</div>
<div id="img">
<img src"....">
<p>TitleCat</p>
</div>
<div id="img">
<img src"....">
<p>TitleDog</p>
</div>
</div>
I will need to create a function sortImage()
, but i am not sure how to
approach it.