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?

Junior Mayhé
  • 15,769
  • 26
  • 111
  • 159
Rickstar
  • 5,787
  • 21
  • 53
  • 74

1 Answers1

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);
});
Nick Craver
  • 610,884
  • 134
  • 1,288
  • 1,151
  • how would i get only the file name not the whole address? – Rickstar Oct 14 '10 at 13:34
  • @Gully - There's a few easy options for that, check out these questions: http://stackoverflow.com/questions/605696/get-file-name-from-url, http://stackoverflow.com/questions/1302306/how-to-pull-the-file-name-from-a-url-using-javascript-jquery – Nick Craver Oct 14 '10 at 13:36