1

i have 3 images with the same id="UserImages" i wanted to know if i can click on them and get the scr in jquery?

1
  • 3
    An html id attribute cannot have the same value multiple times. Use class attribute. Commented Oct 14, 2010 at 13:21

1 Answer 1

8

First I'd switch them to classes (IDs must be unqiue):

<img class="UserImages" src="..." />

Then use a .class selector to find them, like this:

$("img.UserImages").click(function() {
  alert(this.src);
});
Sign up to request clarification or add additional context in comments.

2 Comments

how would i get only the file name not the whole address?
@Gully - There's a few easy options for that, check out these questions: stackoverflow.com/questions/605696/get-file-name-from-url, stackoverflow.com/questions/1302306/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.