Reputation: 771
I tried:
$("img[src='"+imgSrc+"']")
but it did not work. imgSrc is an absolute path, but the path in the HTML file is relative. Knowing that I can't modify imgSrc
, how can I find images by their absolute path?
Upvotes: 1
Views: 787
Reputation: 1074335
The only thing I can think of is finding the img
elements and looking at their src
property (rather than attribute; they're different for images with relative paths) to pick out the one(s) you want, e.g.:
$("img[src]").each(function() {
// Here, `this.src` will be the absolute path
if (this.src === imageSrc) {
// Do something, and optionally `return false` to break the
// loop if you're done
}
});
Upvotes: 3
Reputation: 8482
Browsers handles paths different. You can use $
in your selector to find images ends with imgSrc
if it solves your problem.
$("img[src$='"+imgSrc+"']")
Upvotes: -1