position:absolute after class changeThe following toggle behavior works with most browsers except Safari. It's intended to simply toggle the class attribute of the target element between "hide" and "show". The CSS of the "hide" class moves the target element out of the document flow to the left of the browser window.
Safari seems to have a sticky position declaration—the position:absolute declaration of the "hide" class holds though the target element's class was changed to "show" via the toggle function. The CSS for the paragraph example below looks like:
.hide {
position:absolute;
left:-999px;
width:999px;
}
div element: [toggle]paragraph element
A CSS declaration of position:relative applied to the target's child element(s) fixes the problem. The additional CSS for the paragraph example would be:
.hide p {
position:relative;
}
div element: [toggle]paragraph element
When changing a parent element's class via JavaScript/DOM, the initial class's position:absolute declaration sticks. The problem is corrected by applying a position:relative declaration to the parent element's children. (2006-09-29)
UPDATE (2006-09-30): Mark Rowe spotted the bug on the WebKit bug database: http://bugzilla.opendarwin.org/show_bug.cgi?id=7095.