I have the following legacy code that creates an “auto-complete” popup when I enter a form using the results from an AJAX call. This code works fine in Firefox 6 and IE9 - it outputs a little div (style is what Chrome shows in the developer tools):
<div id="theDiv" style="position: absolute; left: 0px; top: 21px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: green; border-right-color: green; border-bottom-color: green; border-left-color: green; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-image: initial; background-color: white; z-index: 1; visibility: hidden; "><div style="visibility: visible; ">[...autocomplete text here...]</div></div>
I see this <div>in FF and IE, but Chrome shows <div>which seems to be crashing to its borders. Oddly enough, if I set a breakpoint using the developer tools in the javascript code below in the line this.oDiv.style.visibility = "visible";, Chrome will create <div>and show it with the size of the minimized-down-to-borders, but if I go to the Elements tab in the Developer Tools to try to understand , why, it seems, something is recounting Chrome, and mine <div>suddenly appears and displays correctly. If I update, everything will break again.
Is this a Chrome bug, or is there something wrong with my code?
Relevant Code:
AutoComplete.prototype.onchange = function()
{
while ( this.oDiv.hasChildNodes() )
this.oDiv.removeChild(this.oDiv.firstChild);
var aStr = new Array();
this.db.getStrings("", "", aStr);
var i, n = aStr.length;
for ( i = 0; i < n; i++ )
{
var iDiv = document.createElement('div');
var myText = document.createTextNode(aStr[i]);
iDiv.appendChild(myText);
iDiv.FormName = this.FormName;
iDiv.onmousedown = AutoComplete.prototype.onDivMouseDown;
iDiv.onmouseover = AutoComplete.prototype.onDivMouseOver;
iDiv.onmouseout = AutoComplete.prototype.onDivMouseOut;
iDiv.AutoComplete = this;
iDiv.style.visibility = "visible";
this.oDiv.appendChild(iDiv);
}
this.oDiv.style.visibility = "visible";
}
source
share