Homam
Homam

Reputation: 23871

How to get an image by its source?

How can I write client javascript to get an image by its source ?

Upvotes: 1

Views: 313

Answers (2)

ChevCast
ChevCast

Reputation: 59234

Use JQuery.

$("img[src='imageurl.jpg']")

Upvotes: 0

user113716
user113716

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

Related Questions