views:

18

answers:

1

I have two lists with images, Album and Favorites.
When clicking on a thumbnail in the Album I want to check if that image is already in the Favorites list.

I tried using :contains but returns false everytime. example here: http://jsfiddle.net/tunafish/yJ95f/1/

Is :contains the right option or should I go with real arrays?
The image lists are not long, max 20.

HTML:

<div id="album">
    <p>Photo Album</p>
    <ul class="gallery">
        <li><img src="001.jpg" /></li>
        <li><img src="002.jpg" /></li>
        <li><img src="003.jpg" /></li>
        <li><img src="004.jpg" /></li>
        <li><img src="005.jpg" /></li>
    </ul>
</div> 
<div id="favorites">
    <p>Favorites</p>    
    <ul class="gallery">
         <li><img src="001.jpg" /></li>
         <li><img src="002.jpg" /></li>
         <li><img src="010.jpg" /></li>
    </ul>
</div>

JS:

$("#album li img").click(function() {
    var url = $(this).attr('src');
    alert(isFavorite(url));
})
function isFavorite(url) {
    return $("#favorites li img[src]:contains(" + url + ")").length > 0;
}
A: 

try:

function isFavorite(url) {
  return $("#favorites li img[src*='" + url + "']").length > 0;
}
Shay Erlichmen
that's great! cheers Shay.
FFish