Say you have an element like this:
<code id="mycode"></code>
You can do it like this:
$("#mycode").append($("<div />").append($('img').clone()).html());
Or if you want it semi-encoded for display, like this:
var html = $("<div />").append($('img').clone()).html();
$("#mycode").append(html.replace('<','<').replace('>','>'));
You can give that a try here. The getting the html portion itself is available in plugin form as well, here and here, the encoding, if you need it, you'll have to do yourself, or get a syntax plugin.