Reputation: 23871
How can I write client javascript to get an image by its source ?
Upvotes: 1
Views: 313
Reputation: 322582
An image that is on the page?
You can do this with jQuery:
<body>
<!-- your content including the image -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var myimg = $('img[src="/some/path/to/img.jpg"]');
});
</script>
</body>
This uses the tag-selector
(docs) along with the attribute-equals-selector
(docs) to get img
elements where the src
matches the source you want.
Upvotes: 5