I am trying to use jQuery to fade out a div using the fadeOut function. In most cases, this works fine, but in some cases, not all content disappears. If I have an absolutely positioned element and a floating element inside a div, the fadeOut function does not work. If I have an absolutely positioned element, this will not work. But if I have an absolutely positioned element and an unshielded element, it works. This may seem difficult to explain, but you can try it yourself using this test code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <title>jQuery fadeOut test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> </head> <body> <div id="testBox1" style="position: relative"> <div>test</div> <p style="position: absolute; left: 0; top: 0">This text should fade out.</p> </div> <br><br> <button type="button" onclick="$('#testBox1').fadeOut()">fade out</button> <hr> <div id="testBox2" style="position: relative"> <div style="float: left">test</div> <p style="position: absolute; left: 0; top: 0">This text should fade out.</p> </div> <br><br> <button type="button" onclick="$('#testBox2').fadeOut()">fade out</button> <hr> <div id="testBox3" style="position: relative"> <p style="position: absolute; left: 0; top: 0">This text should fade out.</p> </div> <br><br> <button type="button" onclick="$('#testBox3').fadeOut()">fade out</button> </body></html>
A working example is here (add / edit to the url to play with the example).
Everything works fine in IE7, but in Firefox and Chrome I get strange behavior. Can anyone understand why? Am I doing something wrong, or is it a browser error or an error in jQuery?
source share