By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Element.prototype in IE6

P: n/a
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(eva l('/'+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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Kae Verens wrote:

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(eva l('/'+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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
Martin Honnen wrote:
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
Jul 23 '05 #3

P: n/a
Kae Verens <ka*@verens.com> wrote in message news:<ok*******************@news.indigo.ie>...
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(eva l('/'+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


Sucks, don't it? :(

http://webfx.eae.net/dhtml/ieemu/js.html
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.