Replace img src inside a 'this' object?
Alright so I have a link that is clicked...once it is clicked I want the img src that's within the 'a' attribute to be changed. Here is what I have
HTML:
- <td>
- <a href='#' class='flag' name='$files[id]' >
- <img src='www.somesite.com/images/unflagged.png' class='flagimg' />
- </a>
- </td>
jQuery:
- $(".flag").on("click", function(e){
- var fileID = $(this).attr("name");
- var src = 'www.somesite.com/images/flagged.png';
- $(this).find(".flagimg").attr("src", src);
- return false;
- });
I know it works because when I use
- $('.flagimg').attr("src", src);
it works...but it changes all of my images with the class 'flagimg'. I want it to change the one that was clicked and that's it.