473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Setting an element's class w/ js

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?

Sep 12 '06 #1
8 4825
eg****@gmail.com wrote:
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.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 12 '06 #2
Here, take a look:

http://www.eggce.com

<a href="http://www.eggce.com">http://www.eggce.com</a>
David Dorward wrote:
eg****@gmail.com wrote:
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.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 12 '06 #3
eg****@gmail.com wrote:
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.
Sep 12 '06 #4
eg****@gmail.com wrote:
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
Sep 12 '06 #5
eg****@gmail.com wrote:
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.
David Dorward wrote:
eg****@gmail.com wrote:
<snip>

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

Richard.

Sep 12 '06 #6
JRS: In article <ee*******************@news.demon.co.uk>, dated Tue, 12
Sep 2006 23:49:33 remote, seen in news:comp.lang.javascript, David
Dorward <do*****@yahoo.composted :
>eg****@gmail.com wrote:
>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.
Sep 14 '06 #7
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 14 '06 #8
Dr John Stockton wrote:
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
Sep 14 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: AndyG | last post by:
I'm trying to mess about with a table using javascript. I'm deleting the current row then adding a new row and adding a couple of columns. I then want to add either a style attribute and add a...
9
by: netclectic | last post by:
I'm dynamically adding options to a select list in javascript and i need to be able to set the height of the option, but setting style.height has not effect, I also tried style.pixelHeight but no...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
4
by: Hollywood | last post by:
I'm using XML serialization to produce the following XML document: <TestDoc xmlns:srd="some-url"> <Additional> <Security> <srd:Login>login_id</srd:Login> <srd:Password>password</srd:Password>...
5
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
2
by: Sebastian Araya | last post by:
Hello, I'm trying to create a single function to append new nodes to a DOMDocument object: public function addElement( $element, $name, $value = '', $attrs = Null ) { if( !( $created =...
2
by: anathema | last post by:
this is not specifically behaviour related, but i thought i would risk asking anyway. i am working on a script that triggers a blind down or blind up effect by clicking on a particular link. it...
3
by: Valvalis | last post by:
Hello, I am trying to set a class attribute of a text.item element to the value of its nearest ancestor. I want to do this in the case that the class of the text.item is currently a blank string....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.