Connecting Tech Pros Worldwide Forums | Help | Site Map

javascript and IE style

Grzegorz Ślusarek
Guest
 
Posts: n/a
#1: May 10 '06
Hi all. I have to create a part of me site by javascript code (must
create div that contain 2 divs and these divs must be horizontal on the
page). So here is the part of js code:
divMain = document.createElement('div');
div1= document.createElement('div');
div1.id = 'prev';
div1.style.cssFloat = 'left';
div1.appendChild(document.createTextNode("<"))
divMain.appendChild(div1);
div2= document.createElement('div');
div2.style.cssFloat = 'left';
div2.id = 'next';
div2.appendChild(document.createTextNode(">"))
divMain.appendChild(div2);
of course FF and OPERA interpreted code properly and I get two divs
placed one next to other (< >) but Internet Explorer makes something
like that:
<[color=blue]
>[/color]
So can anyone please tell me what I'm doing wrong? How can I deal with that?
Thanks for any help
Gregor

VK
Guest
 
Posts: n/a
#2: May 10 '06

re: javascript and IE style



Grzegorz Slusarek wrote:[color=blue]
> Hi all. I have to create a part of me site by javascript code (must
> create div that contain 2 divs and these divs must be horizontal on the
> page). So here is the part of js code:
> divMain = document.createElement('div');
> div1= document.createElement('div');
> div1.id = 'prev';
> div1.style.cssFloat = 'left';[/color]

cssFloat ?

div1.style.float = 'left';

Actually layout/styling problem are better suited to
<comp.infosystems.www.authoring.stylesheets>

Richard Cornford
Guest
 
Posts: n/a
#3: May 10 '06

re: javascript and IE style


Grzegorz Slusarek wrote:[color=blue]
> Hi all. I have to create a part of me site by javascript code (must
> create div that contain 2 divs and these divs must be horizontal on the[/color]
<snip>[color=blue]
> div1.style.cssFloat = 'left';[/color]
<snip>

Because 'float' is a reserved word in javascript (and many other
programming languages as well), so it could not appear in a dot
notation property accessor at all, when the W3C needed to provide a
property of style objects to set the CSS - float - they decided that it
should be called 'cssFloat'. However, Microsoft decided to call the
equivalent property of their style object 'styleFloat'. So on IE you
set the equivalent as:-

div1.style.styleFloat = 'left';

- or do:-

div1.style.cssFloat = div1.style.styleFloat = 'left';

- to cover both IE and W3C versions.

Richard.

Matt Kruse
Guest
 
Posts: n/a
#4: May 10 '06

re: javascript and IE style


Grzegorz Ślusarek wrote:[color=blue]
> div1= document.createElement('div');[/color]

First of all, why not make them spans instead, since they are in-line?
[color=blue]
> div1.style.cssFloat = 'left';[/color]

For IE, use styleFloat. You can ssafely set both properties to satisfy both
browsers.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


VK
Guest
 
Posts: n/a
#5: May 10 '06

re: javascript and IE style



VK wrote:[color=blue]
> Grzegorz Slusarek wrote:[color=green]
> > Hi all. I have to create a part of me site by javascript code (must
> > create div that contain 2 divs and these divs must be horizontal on the
> > page). So here is the part of js code:
> > divMain = document.createElement('div');
> > div1= document.createElement('div');
> > div1.id = 'prev';
> > div1.style.cssFloat = 'left';[/color]
>
> cssFloat ?
>
> div1.style.float = 'left';[/color]

As others pointed out, I wrote b.s. Sorry, just forgot this exception.
Yes, for IE .styleFloat, for others .cssFloat.

That reminded me of a noticeable script rules change in Firefox 1.5x
The engine doesn't care anymore of reserved words if they are "future
reserved"
var obj = new Object();
obj.float = 'foo';
obj.class = 'bar';
alert(obj.class);
goes just fine.

IE6 acts in the most weird way here: it simply stops any further script
execution but it doesn't show any errors.
[color=blue]
> Actually layout/styling problem are better suited to
> <comp.infosystems.www.authoring.stylesheets>[/color]

That remains true, but in the light of all side issues not a complete
true.

Matt Kruse
Guest
 
Posts: n/a
#6: May 10 '06

re: javascript and IE style


VK wrote:[color=blue][color=green]
>> cssFloat ?
>> div1.style.float = 'left';[/color]
> As others pointed out, I wrote b.s.[/color]

Why would you even bother responding to something if you so clearly don't
know the answer?

"It is better to be silent and thought a fool than to open one's mouth
and remove all doubt." -- Mark Twain

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


VK
Guest
 
Posts: n/a
#7: May 10 '06

re: javascript and IE style



Matt Kruse wrote:[color=blue]
> VK wrote:[color=green][color=darkred]
> >> cssFloat ?
> >> div1.style.float = 'left';[/color]
> > As others pointed out, I wrote b.s.[/color]
>
> Why would you even bother responding to something if you so clearly don't
> know the answer?[/color]

Because at moment of the answer I thought I knew the answer (list time
I /scripted/ float property in the last century). That happens
sometimes. You too suggested to use inline elements in your response
while it's impossible: float automatically switch the display to
"block" ;-)

Richard Cornford
Guest
 
Posts: n/a
#8: May 10 '06

re: javascript and IE style


VK wrote:[color=blue]
> Matt Kruse wrote:[color=green]
>> VK wrote:[color=darkred]
>> >> cssFloat ?
>> >> div1.style.float = 'left';
>> > As others pointed out, I wrote b.s.[/color]
>>
>> Why would you even bother responding to something if you so
>> clearly don't know the answer?[/color]
>
> Because at moment of the answer I thought I knew the answer[/color]

That is a recurring theme in your posts, you believe you know what you
are talking about when it is very evident that you almost never do. The
annoying thing is that you invariable still believe that you know what
you are talking about after you have been shown that you are wrong.
[color=blue]
> (list time I /scripted/ float property in the last century).[/color]

Excuses, excuses. You claim to be a programmer but that does not seem
credible when you do not see instantly that 'float' is unlikely to be
available for use as an Identifier. And if you were scripting float in
the last century you obviously did not understand why you were using
'styleFloat' and 'cssFloat' instead of 'float' or it would not be so
easy to forget.
[color=blue]
> That happens sometimes.[/color]

It has been suggested to you before that a little testing may stop you
from looking quite the fool you currently do. Just come to terms with
the idea that your actual understanding of javascript (and, on recent
evidence, web technologies in general) is at best superficial and mostly
erroneous and you should start to perceive a reason for testing things
before you run off at the mouth about them.
[color=blue]
> You too suggested to use inline elements in your response
> while it's impossible:[/color]

Impossible? A feature of inline elements is that they are laid out
across the display (within their container). Matt's proposal is that if
the elements are inline instead of being block neither will need to
float in order for them to sit next to each other because that is what
they will be inclined to do anyway.
[color=blue]
> float automatically switch the display to
> "block" ;-)[/color]

Which is irrelevant if they are not floated.

Richard.


Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#9: May 19 '06

re: javascript and IE style


Richard Cornford wrote:
[color=blue]
> div1.style.styleFloat = 'left';
>
> - or do:-
>
> div1.style.cssFloat = div1.style.styleFloat = 'left';
>
> - to cover both IE and W3C versions.[/color]

I recommend against the latter because `style' is a reference
to another host object (that may not allow augmentation).


PointedEars
--
Alcohol and Math don't mix. So please don't drink and derive!
Closed Thread