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?
Asked
Active
Viewed 322 times
1
-
3An html id attribute cannot have the same value multiple times. Use class attribute. – Chris Oct 14 '10 at 13:21
1 Answers
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
-
-
@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