RE: Event binding/this problem

"Seb Frost" <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
cheers Scott, I have the following functions I use normally, I just stripped
them out for the example in the email:

they work in firefox for me.

function addClass(e,c)
{
	if (e.className==undefined)
		e.className = c;
	else
		e.className += ' ' + c;
}

function delClass(e,c)
{
	if (e.className!=undefined)
		if (e.className.split(' ').length > 1)
			e.className = e.className.replace(new RegExp(' ' + c + '\\b'), '');
		else
			e.className = e.className.replace(new RegExp(c + '\\b'),'');
}

function hasClass(e,c)
{
	cs = e.className.split(' ');

	for(var i=0; i<cs.length; i++)
		if (cs[i]==c) return true;

	return false;
}




-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf
Of Scott Sauyet
Sent: 09 November 2005 16:57
To: [email protected]
Subject: Re: [wdf-dom] Event binding/this problem


Seb Frost wrote:
> thankyou guys, all been very helpful.

To make up for my boneheaded first response (who thinks in global
variables these days?!) I'd like to point out that there might be a
slight problem in Firefox, depending upon whether your element already
has an HTML class.  The attached does not work properly in Firefox.  For
some reason, the node.className += " over" seems to make node.className
into "over" (without the space.)

This will work, though, regardless of whether you have an existing class
name:

     element.className = element.className.replace(/\bover\b/, "");

But I prefer to do it like this:

     element.className = element.className.replaceWord("over", "");

using this:

String.prototype.replaceWord = function(original, replacement) {
     regex = new RegExp("\\b" + original + "\\b");
     return this.replace(regex, replacement);
};

   -- Scott


[Non-text portions of this message have been removed]




Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html
Yahoo! Groups Links








------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~-> 

Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.