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é
  • 16,144
  • 26
  • 115
  • 161
Rickstar
  • 6,057
  • 21
  • 55
  • 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
  • 623,446
  • 136
  • 1,297
  • 1,155
  • 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