Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

FILTERIZR jquery plugin

i am really stuck on this project 4 on front-end developer tech degree. so basically the assignment is simple : integrate 2 jquery plugins ( 1 lightbox and 1 for search/ filter some pictures ). i found that the lightbox was very simple to implement but the search filter one seems impossible i just need some help what am i doing wrong ?

here is the html code :

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8">
    <title>Interactive Photo Gallery</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/lightbox.css">
    <link rel="stylesheet" type="text/css" href="scripts/lightbox2-master/css/lightbox.css">
</head>
<body>
  <div id="content">
    <input type="text" name="search" placeholder="Search..." data-search>
    <div class="filtr-container">
      <div class="filtr-item" data-category="1" data-sort="unu">
        <a href="pics/01.jpg" title="Hay Bales" data-filter="all" data-lightbox="portfolio" data-type="vegan pizza" data-title="I love hay bales. Took this snap on a drive through the countryside past some straw fields."><img src="pics/thumbnails/01.jpg" class="name" alt="I love hay bales. Took this snap on a drive through the countryside past some straw fields."></a>
      </div>
      <div class="filtr-item" data-category="1, 2" data-sort="doi">
        <a href="pics/02.jpg" title="Lake" data-lightbox="portfolio" data-title="The lake was so calm today. We had a great view of the snow on the mountains from here."><img src="pics/thumbnails/02.jpg" alt="The lake was so calm today. We had a great view of the snow on the mountains from here."></a>
      </div>
      <div class="filtr-item" data-category="1, 3" data-sort="trei">
        <a href="pics/03.jpg" title="Canyon" data-lightbox="portfolio" data-title="I hiked to the top of the mountain and got this picture of the canyon and trees below."><img src="pics/thumbnails/03.jpg" alt="I hiked to the top of the mountain and got this picture of the canyon and trees below."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="patru">
        <a href="pics/04.jpg" title="Iceberg" data-lightbox="portfolio" data-title="It was amazing to see an iceberg up close, it was so cold but didn’t snow today."><img src="pics/thumbnails/04.jpg" alt="It was amazing to see an iceberg up close, it was so cold but didn’t snow today."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="cinci">
        <a href="pics/05.jpg" title="Desert" data-lightbox="portfolio" data-title="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons."><img src="pics/thumbnails/05.jpg" alt="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="sase">
        <a href="pics/06.jpg" title="Fall" data-lightbox="portfolio" data-title="Fall is coming, I love when the leaves on the trees start to change color."><img src="pics/thumbnails/06.jpg" alt="Fall is coming, I love when the leaves on the trees start to change color."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="sapte">
        <a href="pics/07.jpg" title="Plantation" data-lightbox="portfolio" data-title="I drove past this plantation yesterday, everything is so green!"><img src="pics/thumbnails/07.jpg" alt="I drove past this plantation yesterday, everything is so green!"></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="opt">
        <a href="pics/08.jpg" title="Dunes" data-lightbox="portfolio" data-title="My summer vacation to the Oregon Coast. I love the sandy dunes!"><img src="pics/thumbnails/08.jpg" alt="My summer vacation to the Oregon Coast. I love the sandy dunes!"></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="noua">
        <a href="pics/09.jpg" title="Countryside Lane" data-lightbox="portfolio" data-title="We enjoyed a quiet stroll down this countryside lane."><img src="pics/thumbnails/09.jpg" alt="We enjoyed a quiet stroll down this countryside lane."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="zece">
        <a href="pics/10.jpg" title="Sunset" data-lightbox="portfolio" data-title="Sunset at the coast! The sky turned a lovely shade of orange."><img src="pics/thumbnails/10.jpg" alt="Sunset at the coast! The sky turned a lovely shade of orange."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="unspe">
        <a href="pics/11.jpg" title="Cave" data-lightbox="portfolio" data-title="I did a tour of a cave today adn the view of the landscape below was breathtaking."><img src="pics/thumbnails/11.jpg" alt="I did a tour of a cave today adn the view of the landscape below was breathtaking."></a>
      </div>
      <div class="filtr-item" data-category="1" data-sort="doispe">
        <a href="pics/12.jpg" title="Bluebells" data-lightbox="portfolio" data-title="I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in."><img src="pics/thumbnails/12.jpg" alt="I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in."></a>
      </div>
    </div>
  </div>
    <script>
    var filterizd = $('.filtr-container').filterizr({
   //options object
});
    </script>
    <script type="text/javscript" src="scripts/main.js"></script>
    <script type="text/javascript" src="scripts/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="scripts/lightbox.js"></script>
    <script type="text/javascript" src="scripts/jquery.filterizr.min.js"></script>
</body>
</html>  

the jquery plugin that i am trying to implement can be found here http://yiotis.net/filterizr/

Hey Daniel, did you ever get your code to work? I am using this exact same plugin as you for my search box.

4 Answers

In addition to Konrad's answer.

The problem is with the jQuery version.it seems that this plugin is not compatible with 3.0 an higher. Just change the jquery version to something later than 3.0 and it should run fine. I hope this helps.

When you using multiple scripts on your website, you have to make sure that they're linked in corect order. In your code you're trying initialize filterizr, before even jQuery is loaded. Every time you using javascript plugins on your sites make sure that your own js code is loaded at the very end of your page, you could also use script tag defer attribute so js would not block rendering of your page while scripts are being downloaded, but this is optional.

Change the order of your scripts to something like that:

<script type="text/javascript" src="scripts/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="scripts/jquery.filterizr.min.js"></script>
<script type="text/javascript" src="scripts/lightbox.js"></script>
<script type="text/javscript" src="scripts/main.js"></script>
<script>
var filterizd = $('.filtr-container').filterizr({
   //options object
});
</script>

BTW. nice filter plugin

Hello guys, I am working on this exact same project dealing with the exact same problem. I am using filterizr as well and I cannot get my images to filter as I search them into the text box either. If you guys can assist me with this issue it would be greatly appreciated. :)

here is my code

html

<!DOCTYPE html>
<html>
<head>
<title>Jquery project</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="lightbox/src/imagelightbox.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>

<input type="text" id="filter" name="photo-search" placeholder="Search(16pt)" data-search>

<div class="filtr-container">
<ul id="thumbnails">

<div class="filtr-item" data-category="Hay Bales" data-sort="Hay Bales">
<li><a  href="photos/01.jpg" data-imagelightbox="demo" data-ilb2-caption="Hay Bales I love hay bales. Took this snap on a drive through the countryside past some straw fields"><img src="images/01.jpg" alt="Hay Bales" title="1st Photo"></a></li>
<div>

<div class="filtr-item" data-category="Lake" data-sort="Lake">
<li><a class="caption" href="photos/02.jpg"data-imagelightbox="demo"  data-ilb2-caption="The lake was so calm today. We had a great view of the snow on the mountains from here"><img src="images/02.jpg" alt="Lake" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Canyon" data-sort="Canyon">
<li><a class="caption"href="photos/03.jpg" data-imagelightbox="demo" data-ilb2-caption="I hiked to the top of the mountain and got this picture of the canyon and trees below."><img src="images/03.jpg" alt="
Canyon" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Iceberg" data-sort="Iceberg">
<li><a class="caption"href="photos/04.jpg" data-imagelightbox="demo" data-ilb2-caption="It was amazing to see an iceberg up close, it was so cold but didn’t snow today."><img src="images/04.jpg" alt="Iceberg
" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Desert" data-sort="Desert">
<li><a class="caption"href="photos/05.jpg" data-imagelightbox="demo" data-ilb2-caption="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons."><img src="images/05.jpg" alt="
Desert" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Fall" data-sort="Fall">
<li><a class="caption"href="photos/06.jpg" data-imagelightbox="demo" data-ilb2-caption="
Fall is coming, I love when the leaves on the trees start to change color."><img src="images/06.jpg" alt="
Fall" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Plantation" data-sort="Plantation">
<li><a class="caption"href="photos/07.jpg" data-imagelightbox="demo" data-ilb2-caption="
I drove past this plantation yesterday, everything is so green!
"><img src="images/07.jpg" alt="Plantation" title="1st Photo"></a></li>
</div>

<div class="filtr-item" data-category="Dunes" data-sort="Dunes">
<li><a class="caption"href="photos/08.jpg" data-imagelightbox="demo" data-ilb2-caption="
My summer vacation to the Oregon Coast. I love the sandy dunes!
"><img src="images/08.jpg" alt="
Dunes" title="1st Photo"></a></li>
<div>


<div class="filtr-item"data-category="Countryside" data-sort="Countryside">
<li><a "href="photos/09.jpg" data-imagelightbox="demo" data-ilb2-caption="Lane
We enjoyed a quiet stroll down this countryside lane."><img src="images/09.jpg" alt="
Countryside" title="1st Photo"></a></li>
<div>

<div class="filtr-item" data-category="" data-sort="Sunset">
<li><a class="caption"href="photos/10.jpg" data-imagelightbox="demo" data-ilb2-caption="Sunset at the coast! The sky turned a lovely shade of orange."><img src="images/10.jpg" alt="
Sunset" title="1st Photo"></a></li>
<div>

<div class="filtr-item" data-category="Cave" data-sort="Cave">
<li><a class="caption"href="photos/11.jpg" data-imagelightbox="demo" data-ilb2-caption="I did a tour of a cave today and the view of the landscape below was breathtaking."><img src="images/11.jpg" alt="Cave" title="1st Photo"></a></li>
</div>


<div class="filtr-item" data-category="Bluebells" data-sort="Bluebells">
<li><a class="caption"href="photos/12.jpg" data-imagelightbox="demo" data-ilb2-caption="
I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in."><img src="images/12.jpg" alt="Bluebells" title="1st Photo"></a></li>
</div>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="lightbox/src/imagelightbox.js"></script>
<script src="js/apps.js"></script>
<script src="filterizr-master/jquery.filterizr.min.js"></script>

<script>
var filterizd = $('.content-photos').filterizr({

});
</script>
</body>
</html>

Hi Taran, I have looked on your code. At first you have some bug in your code.

  1. Double quotes typo near href="photos/09.jpg"
  2. Delete ul and li's, this is very unsemantic to put div right inside your ul element.
<ul>
<div><li>MEGA BAD</li></div>
</ul>
<ul>
<li><div>GOOD</div></li>
</ul>
  1. You're pointing to empty set with your .content-photos selector in jQuery expression
  2. At last you have to put text into your anchor elements(not as attributes) to make your search work

Hope this helps GL & HF

Hey Konrad, Thank you for the feedback. I have not gotten the code to work as needed but I have made some changes to my code based on your suggestions. This is what my code looks like now, do you still see more issues with the code. Thank you.

html

<!DOCTYPE html>
<html>
<head>
<title>Jquery project</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="lightbox/src/imagelightbox.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>

<input type="text" id="filter" name="photo-search" placeholder="Search(16pt)" data-search>

<div class="filtr-container">

<ul id="thumbnails">

<li><div class="filtr-item" data-category="Hay Bales" data-sort="Hay Bales"> <a href="photos/01.jpg" data-imagelightbox="demo" data-ilb2-caption="Hay Bales I love hay bales. Took this snap on a drive through the countryside past some straw fields"></div><img src="images/01.jpg" alt="Hay Bales" title="1st Photo"></a></li>

<li><div class="filtr-item" data-category="Lake" data-sort="Lake"><a class="caption" href="photos/02.jpg"data-imagelightbox="demo"  data-ilb2-caption="The lake was so calm today. We had a great view of the snow on the mountains from here"></div><img src="images/02.jpg" alt="Lake" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Canyon" data-sort="Canyon"><a href="photos/03.jpg" data-imagelightbox="demo" data-ilb2-caption="I hiked to the top of the mountain and got this picture of the canyon and trees below."></div><img src="images/03.jpg" alt="
Canyon" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Iceberg" data-sort="Iceberg"><a href="photos/04.jpg" data-imagelightbox="demo" data-ilb2-caption="It was amazing to see an iceberg up close, it was so cold but didn’t snow today."></div><img src="images/04.jpg" alt="Iceberg
" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Desert" data-sort="Desert"><a href="photos/05.jpg" data-imagelightbox="demo" data-ilb2-caption="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons."></div><img src="images/05.jpg" alt="
Desert" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Fall" data-sort="Fall"><a href="photos/06.jpg" data-imagelightbox="demo" data-ilb2-caption="Fall is coming, I love when the leaves on the trees start to change color."></div><img src="images/06.jpg" alt="
Fall" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Plantation" data-sort="Plantation"><a class="caption"href="photos/07.jpg" data-imagelightbox="demo" data-ilb2-caption="I drove past this plantation yesterday, everything is so green!"></div><img src="images/07.jpg" alt="Plantation" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="Dunes" data-sort="Dunes"><a href="photos/08.jpg" data-imagelightbox="demo" data-ilb2-caption="My summer vacation to the Oregon Coast. I love the sandy dunes!"></div><img src="images/08.jpg" alt="Dunes" title="1st Photo"></a></li>




<li><div class="filtr-item"data-category="Countryside" data-sort="Countryside"><a href="photos/09.jpg" data-imagelightbox="demo" data-ilb2-caption="LaneWe enjoyed a quiet stroll down this countryside lane."></div><img src="images/09.jpg" alt="Countryside" title="1st Photo"></a></li>



<li><div class="filtr-item" data-category="" data-sort="Sunset"><a href="photos/10.jpg" data-imagelightbox="demo" data-ilb2-caption="Sunset at the coast! The sky turned a lovely shade of orange."></div><img src="images/10.jpg" alt="Sunset" title="1st Photo"></a></li>


<div class="filtr-item" data-category="Cave" data-sort="Cave">
<li><div class="filtr-item" data-category="Cave" data-sort="Cave"><a href="photos/11.jpg" data-imagelightbox="demo" data-ilb2-caption="I did a tour of a cave today and the view of the landscape below was breathtaking."><img src="images/11.jpg" alt="Cave" title="1st Photo"></a></li>
</div>



<li><div class="filtr-item" data-category="Bluebells" data-sort="Bluebells"></div><a href="photos/12.jpg" data-imagelightbox="demo" data-ilb2-caption="I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in."><img src="images/12.jpg" alt="Bluebells" title="1st Photo"></a></li>



</ul>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="lightbox/src/imagelightbox.js"></script>
<script src="js/apps.js"></script>
<script src="filterizr-master/jquery.filterizr.min.js"></script>

<script>
var filterizd = $('.content-photos').filterizr({

});
</script>
</body>
</html>
  1. Still recommending you to delete those ul and li tags, if you wont, you will have to set class of your li items to filtr-item else plugin wont work.
  2. var filterizd = $('.content-photos') <-- bad selector, should be .filtr-container or #thumbnails
  3. Put text into .filtr-item element to make your search work, you can hide this text in css.
<div class="filtr-item" data-category="1" data-sort="unu">
    <a href="img/01.jpg" title="Hay Bales" data-filter="all" data-lightbox="portfolio" data-type="vegan pizza" data-title="I love hay bales. Took this snap on a drive through the countryside past some straw fields.">
        <img src="img/01.jpg" class="name" alt="I love hay bales. Took this snap on a drive through the countryside past some straw fields.">
        <p>I love hay bales. Took this snap on a drive through the countryside past some straw fields.</p>
    </a>
</div>

If you still having troubles, check my whole solution to searching in filterizd here

Hey Konrad, Thank you for you help once. I have followed your code solution but I have still not gotten the search feature to work. This is what my code looks like now:

<!DOCTYPE html>
<html>
<head>
<title>Jquery project</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="lightbox/src/imagelightbox.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>

<div id="content">

<input type="text" name="search" placeholder="Search(16pt)" data-search>

<div class="filtr-container">


<div class="filtr-item" data-category="1" data-sort="Hay Bales">
<a href="photos/01.jpg" title="Hay bayles" data-imagelightbox="demo" data-ilb2-caption="Hay Bales I love hay bales. Took this snap on a drive through the countryside past some straw fields">
<img src="images/01.jpg" alt="Hay Bales" title="hay bayles">
<p>Hay bales</p> 
</a>
</div>

<div class="filtr-item" data-category="1,2" data-sort="Lake">
<a href="photos/02.jpg" title="Lake" data-filter="all" data-imagelightbox="demo"  data-ilb2-caption="The lake was so calm today. We had a great view of the snow on the mountains from here">
<img src="images/02.jpg" alt="Lake" title="1st Photo">
<p>lake</p>
</a>
</div>


<div class="filtr-item" data-category="1,3" data-sort="Canyon">
<a href="photos/03.jpg" title="Canyon"data-imagelightbox="demo" data-ilb2-caption="I hiked to the top of the mountain and got this picture of the canyon and trees below."><img src="images/03.jpg" alt="Canyon" title="1st Photo">
<p>canton</p>
</a>

</div>



<div class="filtr-item" data-category="1" data-sort="Iceberg">
<a href="photos/04.jpg" title="Iceberg"data-imagelightbox="demo" data-ilb2-caption="It was amazing to see an iceberg up close, it was so cold but didn’t snow today."><img src="images/04.jpg" alt="Iceberg
" title="1st Photo">
<p>Iceburg</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Desert">
<a href="photos/05.jpg" title="Desert" data-imagelightbox="demo" data-ilb2-caption="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons."><img src="images/05.jpg" alt="
Desert" title="1st Photo">
<p>Desert</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Fall">
<a href="photos/06.jpg" title="Fall" data-imagelightbox="demo" data-ilb2-caption="Fall is coming, I love when the leaves on the trees start to change color.">
<img src="images/06.jpg" alt="Fall" title="1st Photo">
<p>Fall</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Plantation">
<a href="photos/07.jpg" title="Plantation" data-imagelightbox="demo" data-ilb2-caption="I drove past this plantation yesterday, everything is so green!">
<img src="images/07.jpg" alt="Plantation" title="1st Photo">
<p>Plantation</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Dunes">
<a href="photos/08.jpg" title="Dunes" data-imagelightbox="demo" data-ilb2-caption="My summer vacation to the Oregon Coast. I love the sandy dunes!">
<img src="images/08.jpg" alt="Dunes" title="1st Photo">
<p>Dunes</p>
</a>
</div>




<div class="filtr-item"data-category="1" data-sort="Countryside">
<a href="photos/09.jpg" title="Countryside" data-imagelightbox="demo" data-ilb2-caption="LaneWe enjoyed a quiet stroll down this countryside lane.">
<img src="images/09.jpg" alt="Countryside" title="1st Photo">
<p>Countryside</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Sunset">
<a href="photos/10.jpg" data-imagelightbox="demo" data-ilb2-caption="Sunset at the coast! The sky turned a lovely shade of orange.">
<img src="images/10.jpg" alt="Sunset" title="1st Photo">
<p>Sunset</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Cave">
<a href="photos/11.jpg" title="Cave" data-imagelightbox="demo" data-ilb2-caption="I did a tour of a cave today and the view of the landscape below was breathtaking.">
<img src="images/11.jpg" alt="Cave" title="1st Photo">
<p>Cave</p>
</a>
</div>



<div class="filtr-item" data-category="1" data-sort="Bluebells">
<a href="photos/12.jpg" title="Bluebells" data-imagelightbox="demo" data-ilb2-caption="I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in.">
<img src="images/12.jpg" alt="Bluebells" title="1st Photo">
<p>Bluebells</p>
</a>
</div>



</div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery.filterizr.min.js"></script>
<script src="lightbox/src/imagelightbox.js"></script>
<script src="js/apps.js"></script>

<script>
(function($){
            $(document).ready(function(){
                var filterizd = $(".filtr-container").filterizr({});
            });
        })(jQuery);



</script>

</body>
</html>

do you think it is because your file structure are different from mine?