views:

83

answers:

2

Hi,

In the below code, progressDiv is the DIV which is getting build up. But it is getting build up vertically... i need it horizontally... What shud i do ?

    var progressDiv = document.getElementById('progressDiv')
    var div = document.createElement('div');

    div.style.display = 'block';
    div.style.cssFloat = 'left';
    div.style.width = '10px';
    div.style.height = '10px';
    div.style.backgroundColor = 'red';
    div.style.border = '1px solid black';

    progressDiv.appendChild(div);
    if (progressDiv.childNodes.length == 20)
        while (progressDiv.hasChildNodes())
            progressDiv.removeChild(progressDiv.firstChild);
A: 

div.style.cssFloat = 'left'; should be div.style.float = 'left';

Karl B
sorry..still it comes in same way
anish
Make sure that the containing element is wide enough to hold 20 x 10px.
Karl B
the containing element is wide enough.HEre ..this is a combination of outer and inner div tags...normally it will be aligned vertically. What i need is to align outer div tag horizontally
anish
I don't think it should be, should it? `float` was a "future reserved word" in JavaScript until the just-finalized 5th edition, so `div.style.float` is not a valid construct in nearly any implementation; you'd have to use `div.style["float"]`. But the W3C knew that and so named the property `cssFloat` to avoid that problem in at least CSS2: http://www.w3.org/TR/DOM-Level-2-Style/css.html
T.J. Crowder
Yes - my mistake.
Karl B
A: 

Ah, good old IE. If you make the div a span, set the style to inline-block, and drop the float, it should work:

var progressDiv = document.getElementById('progressDiv');
var span = document.createElement('span');

span.style.display = 'inline-block';
span.style.width = '10px';
span.style.height = '10px';
span.style.backgroundColor = 'red';
span.style.border = '1px solid black';

progressDiv.appendChild(span);
if (progressDiv.childNodes.length == 20) {
    while (progressDiv.hasChildNodes()) {
        progressDiv.removeChild(progressDiv.firstChild);
    }
}

Why a span rather than a div? Because IE doesn't like you to try to inline elements that are block by default, even if you change their display. But it's fine with making default-inline elements blocky.

Don't know if dropping the float will mess up something else you're trying to do, though. But if you're just trying to do a progress bar, it should be fine provided you keep the progressDiv wide enough.

T.J. Crowder
I tried this also... Not working :(
anish
Then the problem lies elsewhere, the above does work: http://pastie.org/786193 Tried Chrome, Firefox, IE7, Safari...
T.J. Crowder