[thelist] Extending Javascript Objects

Martyn Haigh martynh at gmail.com
Fri Aug 19 05:38:46 CDT 2005


Hi,

I'#m trying to make my life a bit easier, and kinda failing.  I've
written a few JavaScript prototype functions and attached them to the
Object :

Object.prototype.getStyle = function(strProperty) {
...
}
Object.prototype.setStyle = function(strPoperty, strValue) {
...
}
Object.prototype.addClass = function(strClass) {
...
}
Object.prototype.removeClass = function(strClass) {
...
}
Object.prototype.replaceClass = function(strOldClass, strNewClass) {
...
}
Object.prototype.classExists = function(strClass) {
...
}

there are two problems:
1, I've read that this isn't a good way of getting things done as it
can really really slow down the javascript and is generally a bad
practice.
2, it doesn't work in IE6

All i want is a nice easy way of manipulating classes and styles on
elements within a page.

Can anyone think of a better way of doing this which will still be as
easy as objElement.addClass("alert"); ?

Cheers

M


More information about the thelist mailing list