We help IT Professionals succeed at work.
Get Started

Real time filtering search bar for image gallery based off caption keywords

Robert Weber
Robert Weber asked
on
78 Views
Last Modified: 2018-03-27
I have 12 photos set up with a search bar above them. I am trying to  get my search bar to filter through the captions and only show the images that contain the keywords the user types in the search bar.

my Js file...

$(document.ready(function(){
  $("#filter").keyup(function(){
    var $filter = $(this).toLowerCase();
    var $caption = $(".imageGallery").attr("data-title");
    var $image = $(".imageGallery img src");
    for ( i = 0; i < $caption.length; i++;) {
      $(this).filter($image);
    } if ( $filter === $caption.each().toLowerCase()){
      $image.show();
    } else {
      $image.hide();
    }
  });
});


and  my html....

<form action="" method="post">
      <fieldset>
        <input type="search" id="filter" name="user_search" placeholder="Search(16pt)">
      </fieldset>
    </form>
    <ul class="imageGallery">
      <li><a href="img/fullsize/01.jpg" data-title="I love hay bales. Took this snap on a drive through the countryside past straw fields." data-lightbox="picture_one"><img src="img/thumb/01.jpg" alt=""></a></li>
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE