searching for a string in javascript
<p>I am working on javascript tool for a client site at the moment, basically the users selects a colour from a drop down list, and the client then wants that image for that colour to be displayed.</p>

<p>There are a view problems however, the system the client uses has no way of adding id's or classes to the image, so I cant just do a simple,</p>

<pre><code>if (select value = a class)
{
    showImage
}
</code></pre>

<p>What I have had to do so far, is add the images colour to the image's <code>alt</code> text, so a image title might typically looks like this:</p>

<blockquote>
  <p>A sock, Green</p>
</blockquote>

<p>So far I have the following code:</p>

<pre><code>$('.information select#colours').change(function(){
    var colour = $(this).val();
});
</code></pre>

<p>On my page there can be any number of product images, and their markup will look like this,</p>

<pre><code>&lt;div class="carousel js" tabindex="0"&gt;
&lt;ul class="alternative_images" style="position: absolute; top: 0px; width: 60px; height: 276px;"&gt;
    &lt;li&gt;
        &lt;a href="/uploaded/thumbnails/db_file_img_4_254x347.jpg"&gt;
            &lt;img alt="Ben Fogle Sock, Grey" src="/uploaded/thumbnails/db_file_img_9_58x79.jpg"&gt;
        &lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
        &lt;a href="/uploaded/thumbnails/db_file_img_4_254x347.jpg"&gt;
            &lt;img alt="Ben Fogle Sock, Green" src="/uploaded/thumbnails/db_file_img_7_58x79.jpg"&gt;
        &lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
        &lt;a href="/uploaded/thumbnails/db_file_img_4_254x347.jpg"&gt;
            &lt;img alt="Ben Fogle Sock, Red" src="/uploaded/thumbnails/db_file_img_5_58x79.jpg"&gt;
        &lt;/a&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p></p>

<p>My question is </p>

<p>1) How can I collate all the colours of the images that are found in the images alt after a comma?
2) How can I then search through those colours to pull back the correct image?</p>

<p>Is there a better way of doing this?                                        </p>
