I apologise if this is the wrong newsgroup for this.
I'm working on a CMS backend, and am having trouble getting IE6 to behave.
I have a large script which works perfectly in Firefox, but does not
work in IE, so I'm trying to figure it out.
The following, for example, works in Firefox:
Element.prototype.addClass=function(cl){ this.className+=' '+cl; }
Element.prototype.removeClass=function(cl){
this.className=el.className.toString().replace(eval('/'+cl+'/'),''); }
with the above, you can create an element:
el=document.createElement('div');
and then assign a class to it arbitrarily:
el.addClass('testClass');
or remove it:
el.removeClass('testClass');
unfortunately, IE6 complains about this, saying that Element is not an
object.
Is there a simple way around this, or am I going to have to rewrite a
huge chunk to account for IE6's quirks?
Kae
> I have a large script which works perfectly in Firefox, but does not
> work in IE, so I'm trying to figure it out.
[quoted text clipped - 4 lines]
> Element.prototype.removeClass=function(cl){
> this.className=el.className.toString().replace(eval('/'+cl+'/'),''); }
> unfortunately, IE6 complains about this, saying that Element is not an
> object.
Yes, indeed, there is no Element object in IE, IE doesn't expose these
functions to script so you can't script the prototypes as you can do in
Mozilla. Opera so far doesn't expose Element either so your strategy
would work only in Mozilla browsers (don't know about Konqueror or
Safari currently).
It is not really clear from the DOM specification whether things like
Element or HTMLElement need to be exposed, sometimes if constants are
exposed these objects are mentioned in the DOM specification e.g. in the
IDL for Node there is
interface Node {
// NodeType
const unsigned short ELEMENT_NODE = 1;
const unsigned short ATTRIBUTE_NODE = 2;
...
and thus the ECMAScript binding then says
Prototype Object Node
The Node class has the following constants:
Node.ELEMENT_NODE
This constant is of type Number and its value is 1.
Node.ATTRIBUTE_NODE
This constant is of type Number and its value is 2.
so from that you could conclude that Node should be exposed to
ECMAScript (and indeed for instance Opera 7.5x does so).
But in general it is questionable whether the ECMAScript binding can be
read to require Element and similar to be exposed and IE5/6 doesn't do
it and is not further developed or fixed so you can't rely on this
feature unless you script for Mozilla only.

Signature
Martin Honnen
http://JavaScript.FAQTs.com/
Kae Verens - 30 Nov 2004 12:26 GMT
>> The following, for example, works in Firefox:
>> Element.prototype.addClass=function(cl){ this.className+=' '+cl; }
>> unfortunately, IE6 complains about this, saying that Element is not an
>> object.
> But in general it is questionable whether the ECMAScript binding can be
> read to require Element and similar to be exposed and IE5/6 doesn't do
> it and is not further developed or fixed so you can't rely on this
> feature unless you script for Mozilla only.
that seems to be what I'm finding.
there is an article which appears to have a workable solution, but I
haven't got it working yet with my own test code:
http://delete.me.uk/2004/09/ieproto.html
Kae
> I apologise if this is the wrong newsgroup for this.
>
[quoted text clipped - 25 lines]
>
> Kae
Sucks, don't it? :(
http://webfx.eae.net/dhtml/ieemu/js.html