JQuery - Select image by alt or title

Thomas Depole picture Thomas Depole · Jan 31, 2012 · Viewed 31.6k times · Source

Hello I need this JQuery to run for the image bellow it. But here's the trick I need to select the image by it's alt, I can't seem to get the JQuery to select it

<script>                                    
 $('img[alt="800px-Red_Bull"]').onload = function() {
 Pixastic.process(img, "desaturate", {average : false});
</script>

<img width="800" height="387" src=".../01/800px-Red_Bull.png" alt="800px-Red_Bull" title="800px-Red_Bull">

Answer

Joseph Silber picture Joseph Silber · Jan 31, 2012

Your problem is not with your selector, it's that you're not using the load event correctly.

Change your code to this:

$('img[alt="800px-Red_Bull"]').load(function() {
    Pixastic.process(img, "desaturate", {average : false});
});