0

I want to be able to get ANY element's html code when I click on it. So far I can only get text elements but I can't get image elements. Here's what I have :

$(document).click(function(event) {
    alert($(event.target).html());      
});

this doesn't work with images tags like <img src="" alt=""/> but only with text .. Can you please tell me how to proceed to get the images element ? Thanks in advance.

Ben
  • 469
  • 2
  • 4
  • 20

1 Answers1

3

I think you need to use outerHTML as fields like image/input(self closing) does not contain html

$(document).click(function(event) {
    alert(event.target.outerHTML);      
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531