[thelist] Extending Javascript Objects
Anthony Ettinger
apwebdesign at yahoo.com
Fri Aug 19 06:02:56 CDT 2005
Not tested in IE6, but it should work:
<!-- //
var fooElem = document.getElementById('foo');
var fooClass = fooElem.className;
//set it
fooElem.className = 'newclass';
var styleBlock = fooElem.style;
//set new font size
fooElem.style.fontSize = '1em';
// -->
<div id="foo" class="bar" style="font-size:
10px;">blah</div>
Here's a list of css properties you can set:
http://www.mozilla.org/docs/dom/domref/dom_style_ref18.html#1002335
--- Martyn Haigh <martynh at gmail.com> wrote:
> 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
> --
>
> * * Please support the community that supports you.
> * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip
> Harvester
> and archives of thelist go to:
> http://lists.evolt.org
> Workers of the Web, evolt !
>
Anthony Ettinger
ph: (408) 656-2473
blog: http://www.chovy.com
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the thelist
mailing list