JQuery - Select image by alt or title
Asked Answered
T

2

6

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">
Tophet answered 31/1, 2012 at 4:53 Comment(3)
I think the problem is that you need to call load and not onload. The selector code looks good.Stickseed
It works for me.Ganda
Note that .../ is not a valid path. ./ is the current directory, ../ is the parent directory. .../ does not exist.Broida
G
18

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});
});
Ganda answered 31/1, 2012 at 4:58 Comment(2)
It doesn't appear to work, I uploaded it to jsfiddle, can you take a look? jsfiddle.net/donvito101/prLtF/1Tophet
@ThomasDepole - there are a bunch of things wrong with that fiddle. First, you never loaded jQuery. Second, you didn't load pixastic so that won't work either. Third you had jsfiddle set to load which will occur after this event. Also, as I recall you can't do inline jQuery declarations on jsFiddle (someone correct me if im wrong). Instead you have to set it to use onready. See that this works - jsfiddle.net/prLtF/2Stickseed
H
2

Try:


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

Horrocks answered 31/1, 2012 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.