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

Filter images in a live search/getting each img tag within the div

So here is a snipet of the html code that should give you an idea of how I set it up:

<div class="item" data-src="img/01.jpg"> <img class="choose" src="img/01.jpg"/> </div>

    <div class="item" data-src="img/02.jpg">
        <img class="choose" src="img/02.jpg"/>
    </div>

and here is the javascript code:

for (i = 1; i <= 12; i++){

var captionText = String( $("img:nth-of-type(" + i + ")").attr("alt") ).toLowerCase();
    var checkText = ($(".searchBox").val().toLowerCase() );


if(captionText.indexOf(checkText)!=-1){       
    $("div.item:nth-of-type(" + i + ")").hide();        

}else{

}

Looking at the console.log I can get the caption only on the first time and after that its undefined. My guess is that nth-of-type is not correct choice/not using the right selectors but I am not sure which jquery I should be using instead. Any help would be greatly appreciated.