Setting an element's class w/ js

E

eggie5

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?
 
D

David Dorward

it is confirmed that the active is
being set as the element's class value.
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.
 
R

Richard Cornford

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.
 
R

Richard Cornford


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.
<snip>

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

Richard.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 12
Sep 2006 23:49:33 remote, seen in David
Dorward said:
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.
 
R

Randy Webb

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top