Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#919 closed bug (invalid)

Dom ready premature execution in IE

Reported by: Arrix Owned by:
Priority: major Milestone:
Component: ajax Version: 1.1
Keywords: dom ready domready Cc:
Blocked by: Blocking:


$(document).ready(fn) may prematurely call fn if innerHTML modification is performed before the document finishes loading. This happens in IE6 and IE7. Firefox and Opera don't have the problem. I haven't tested with Safari yet. jQuery revision: 1261

Observation: Run the page in IE, refresh and again. It will alert 0 in most times. sample code:

<!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">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery domReady premature execution</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
    alert($('#div2').size()); //expected to alert 1

<div id="div1">div1</div>
<script type="text/javascript">
var d = document.getElementById('div1');
d.innerHTML = d.innerHTML; //innerHTML modification before page loads

<div id="div2">div2</div>


Change History (2)

comment:1 Changed 16 years ago by brandon

Resolution: invalid
Status: newclosed

The DOM ready event was created to prevent the above inline code all together.

The fix for this is to actually *use* the document.ready event instead of modifying the DOM before it is ready.

comment:2 Changed 16 years ago by Arrix

I see. It's perfect when you have full control of every piece of javascript code.

Note: See TracTickets for help on using tickets.