This is a continuation of another question : jquery automatic image reload on src attribute update?
Using the following code, I get an AJAX GET call for the new image src location, even when the image doesn’t seem to be in the DOM :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready( function(){
$('#button').click( function(){
var $container = $('#container');
var string = $container.html();
string = string.toString();
var $string = $(string);
$string.attr('src', 'foo');
});
});
</script>
</head>
<body>
<div id='container'><img src='pointIcon.png'/></div>
<button id='button'>Go!</button>
</body>
</html>
Any ideas on how to manipulate $string object without triggering the AJAX call? Have tried .toString(), .stopPropogation(), with no luck so far…
You could try wrapping it in <div style=’display:none’> so that it’s not visible when you parse the string into DOM elements, this might prevent the browser from loading the image. If not, you’ll have to manipulate it using string manipulation, not jQuery, because $(string) will create DOM elements for you which is causing the image to be created and then request the image