Rickstar
Rickstar

Reputation: 6189

How to get the src from image in jquery

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?

Upvotes: 1

Views: 336

Answers (1)

Nick Craver
Nick Craver

Reputation: 630349

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);
});

Upvotes: 8

Related Questions