BUG: Internet Explorer 5.5 Fails When You Access an Element Whose Display Style Is Set to None (294984)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q294984

SYMPTOMS

If you try to modify an element that has its focus and display style set to NONE, you receive the following access violation in the browser:
The instruction at "0x011168db" referenced memory at "0x00000004". The memory could not be "read".

CAUSE

An HTML element cannot have focus while its display style is set to none.

RESOLUTION

There are two ways to work around this problem:
  • Shift the focus away from the element before you set its display style to NONE.
  • Use the window.setTimeout method to delay execution of the code that modifies the hidden element.

    NOTE: The amount of time that you must be set depends on computer's capability. If the delay time is not long enough, Internet Explorer may still fail.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The following code reproduces the behavior:
<html>
<head>
<script language="JavaScript">

	function test()
	{
	    thediv.style.display = "none";
	    thediv.innerHTML = "a";  
	}

        /* 
	*   Use test1() or test2() to show the workarounds.
	*   Just change the function call in the onclick
	*   event of "thediv" to either test1() or test2().
         */ 

	function test1()
	{
	    // Give focus to another element to resolve the problem.
	    inp.focus();    
	    thediv.style.display = "none";
	    thediv.innerHTML = "a";  
	}

	function test2()
	{
		thediv.style.display = "none";
		window.setTimeout("newFunction()", 1000);
	}

	function newFunction()
	{
	    thediv.innerHTML = "a";  
	}

</script>
</head>
<body>


<!-- width and height are necessary to make the div with its layout -->
<div onClick="test();" 
	 id="thediv" 
	 style="width: 500px; height: 30px; border: 1px solid red;"> 
     Click on this div and it will disappear
</div>
<input id="inp" type="text"></input>

</body>
</html>
				

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbbug kbDHTML kbnofix KB294984