Connecting Tech Pros Worldwide Help | Site Map

Setting an element's class w/ js

eggie5@gmail.com
Guest
 
Posts: n/a
#1: Sep 12 '06
Hi,

I'm trying to set the class of an element on my page w/ javascript like
this:

function ResetNavigation(element)
{

element.className = "active";
}



However, the effects of the active class are not showing up. When I add
this code to the above snippet, it is confirmed that the active is
being set as the element's class value.


alert(element.className);



Why won't my style render in the browser?

David Dorward
Guest
 
Posts: n/a
#2: Sep 12 '06

re: Setting an element's class w/ js


eggie5@gmail.com wrote:
Quote:
it is confirmed that the active is
being set as the element's class value.
Quote:
Why won't my style render in the browser?
Probably something to do with specificity, and nothing to do with JS at all,
but lacking a URL its rather hard to say for sure.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
eggie5@gmail.com
Guest
 
Posts: n/a
#3: Sep 12 '06

re: Setting an element's class w/ js


Here, take a look:

http://www.eggce.com

<a href="http://www.eggce.com">http://www.eggce.com</a>


David Dorward wrote:
Quote:
eggie5@gmail.com wrote:
>
Quote:
it is confirmed that the active is
being set as the element's class value.
>
Quote:
Why won't my style render in the browser?
>
Probably something to do with specificity, and nothing to do with JS at all,
but lacking a URL its rather hard to say for sure.
>
--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Richard Cornford
Guest
 
Posts: n/a
#4: Sep 12 '06

re: Setting an element's class w/ js


eggie5@gmail.com wrote:
Quote:
I'm trying to set the class of an element on my page
w/ javascript like this:
>
function ResetNavigation(element)
{
element.className = "active";
}
>
However, the effects of the active class are not showing
up. When I add this code to the above snippet, it is
confirmed that the active is being set as the element's
class value.
>
alert(element.className);
>
Why won't my style render in the browser?
How should anyone know? If, for example, the value you pass to your
function as - element - is not actually an Element then setting its -
className - would not be expected to have any visible effect, but there
is nothing here to tell anyone what values may be being passed to the
function. Then the CSS you are using may have no viable manifestation
(either at all or in the context in which you use it). It may also be
the case that "active" is a problematic name to give a class in CSS, as
the active pseudo-class exists.

Without an demonstration of what you actually are doing any suggested
case can only be speculation.

Richard.


David Dorward
Guest
 
Posts: n/a
#5: Sep 12 '06

re: Setting an element's class w/ js


eggie5@gmail.com wrote:
Quote:
Here, take a look:
>
http://www.eggce.com
>
<a href="http://www.eggce.com">http://www.eggce.com</a>
Please don't top post.

As predicted, the style attribute is more specific then a class selector, so
the background colour from the style attribute wins.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Richard Cornford
Guest
 
Posts: n/a
#6: Sep 12 '06

re: Setting an element's class w/ js


eggie5@gmail.com wrote:
Quote:
Here, take a look:
>
http://www.eggce.com
The - ResetNavigation - function on that page is:-

function ResetNavigation(element)
{
alert(element.className);
link.className = "active";
}

- and so is actually assigning to the className property of an
undeclared variable named - link -, and that is not going to have any
visible manifestation except the error in the javascript console.
Quote:
David Dorward wrote:
Quote:
eggie5@gmail.com wrote:
<snip>

Please do not top-post to comp.lang.javascript.

Richard.

Dr John Stockton
Guest
 
Posts: n/a
#7: Sep 14 '06

re: Setting an element's class w/ js


JRS: In article <ee7di8$llh$1$830fa795@news.demon.co.uk>, dated Tue, 12
Sep 2006 23:49:33 remote, seen in news:comp.lang.javascript, David
Dorward <dorward@yahoo.composted :
Quote:
>eggie5@gmail.com wrote:
>
Quote:
>Here, take a look:
>>
>http://www.eggce.com
>>
><a href="http://www.eggce.com">http://www.eggce.com</a>
>
>Please don't top post.

Please do not use jargon ("top post") which the target is not likely to
understand - you are addressing a user of both gmail and googlegroups -
without providing an adequate reference to a reasonable explanation. It
is both unfriendly and generally futile.

You can cite (with URL) FAQ 2.3 paras 1 & 6, or the appropriate part of
some other reference such as in my sig below.

Be satisfied that the jargon term can be found in the reference, either
by indicating its position therein or at least by checking that a Ctrl-F
search for the exact jargon term will find it.

Richard writes "Please do not top-post...", bur Ctrl-F will not find
"top-post" in his FAQ, and the term is not in RFC 1855.

--
© John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 4 ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Randy Webb
Guest
 
Posts: n/a
#8: Sep 14 '06

re: Setting an element's class w/ js


Dr John Stockton said the following on 9/14/2006 10:22 AM:

Quote:
Richard writes "Please do not top-post...", bur Ctrl-F will not find
"top-post" in his FAQ, and the term is not in RFC 1855.
Richard has an FAQ? And all this time I thought it was the c.l.j FAQ and
he was only the Editor of that FAQ.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
David Dorward
Guest
 
Posts: n/a
#9: Sep 14 '06

re: Setting an element's class w/ js


Dr John Stockton wrote:
Quote:
Please do not use jargon ("top post") which the target is not likely to
understand - you are addressing a user of both gmail and googlegroups -
So probably they can use one of Google's other services to find
http://www.google.com/search?q=top+post

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Closed Thread


Similar JavaScript / Ajax / DHTML bytes