473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Element.prototype in IE6

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
3 4511


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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jonjon | last post by:
Hi, Is there any way of adding a property to an HTML element ? I heard about the "prototype" method but it doesn't work for HTML elements such as Images, or Paragraphs... Netscape implements...
5
by: effendi | last post by:
I wrote a simple script to remove an element of an array but I don't think this is the best way to go about it. I have a list of about five elements seperated by ";" I split the array using...
10
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
2
by: aundro | last post by:
Hello, I've recently been developping a google-maps-like api. Firstly, I started development under Firefox, but I now need to run it under Internet Explorer, and I'm running into a little bit of...
1
by: drnicwilliams | last post by:
The Prototype library gives us the $() operation for converting a DOM element id into the DOM element: $('element-id'). It also appends a bunch of functions to the resulting object. Sometimes...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
4
by: sjkothenbeutel | last post by:
I've been reading through quite a bit regarding this topic but am finding myself confused. Here is the scenario: I have a javascript class defined with methods whereas each has references to...
12
by: Aaron Gray | last post by:
In FF you can define the following ... Element.prototype.getClass = function() { return this.className; /* or whatever */ } Element.prototype.setClass = function(c) { this.className = c; } ...
5
by: laredotornado | last post by:
Hi, Please let me know if there is a better place to which to post this message. I'm trying to use prototype.js and wondering how I use it to find elements on page with class = "myClass"? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.