Prevent "jQuery( html )" from triggering the browser to request images and other referenced content

Posted by Chris Dutrow on Stack Overflow See other posts from Stack Overflow or by Chris Dutrow
Published on 2012-09-09T19:24:08Z Indexed on 2012/09/09 21:38 UTC
Read the original article Hit count: 213

Filed under:
|
|

Using jQuery to create new DOM elements from text.

Example:

jQuery('<div><img src="/some_image.gif"></img></div>');

When this statement is executed, it causes the browser to request the file 'some_img.gif' from the server.

Is there a way to execute this statement so that the resulting jQuery object can be used from DOM traversal, but not actually cause the browser to hit the server with requests for images and other referenced content?

Example:

var jquery_elememnts = jQuery('<div><img class="a_class" src="/some_image.gif"></img></div>');
var img_class = jquery_elememnts.find('img').attr('class');

The only idea I have now is to use regex to remove all of the 'src' tags from image elements and other things that will trigger the browser requests before using jQuery to evaluate the HTML.

How can jQuery be used to evaluate HTML without triggering the browser to make requests to the server for referenced content inside the evaluated HTML?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery