Get Markup of Clicked Image Element

Get Markup of Clicked Image Element

Hi all, I'm trying to get the markup of any clicked image by wrapping it in a span element using the wrap() method. The wrap() method allows you to wrap any text around any specified selector. 

Then I tried to use the html() method on the span element to get the markup of the clicked img element. I plan to later remove the  span tag and temporary id but so far it,s not working. Below is what I have tried.

  1. $(event.target).wrap("<span id='tempSpan'></span>");
  2. imageMarkup = $("#tempSpan").html();

Please point out where I went wrong, thanks in advance.