tags:

views:

34

answers:

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?

+8  A: 

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
how would i get only the file name not the whole address?
Gully
@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