I am using jQuery on DOM elements that are not added to the DOM tree of the actual page, nor will be, to render some HTML and get it as a string.
Minimal example is simply evaluating:
$('<div><img src="foo.png"></div>').html()
Unfortunately, this causes the browser to try to load the image.
How can I prevent this?
This is in the context of a Chrome app, so a chrome-specific solution is acceptable.
In my use case, simply avoiding the DOM elements is not an option: In the actual code, the existing templating machinery uses DOM elements and jQuery to assemble the output. Similarly, I cannot simply replace src
with data-src
.