473,405 Members | 2,338 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,405 software developers and data experts.

DOM help. setAttribute won't work

fj
I have no problem nevigate and neil down the element I want to manipulate.

What I want to do is set the css class of an item according to
window.location (URL). But it doesn't work.

I call this function in
<body onload="SelectMenuItem();" >

here is the function
function SelectMenuItem() {
....
//i is a variable I set before.
var nodes_LI = document.getElementById("TopNav").childNodes;
for (j=0; j<nodes_LI.length; j++) {
nodes_LI[j].firstChild.removeAttribute("class");
}
nodes_LI[i].firstChild.setAttribute("class", "highlighted");
....
}
Jul 23 '05 #1
2 1996
DU
fj wrote:
I have no problem nevigate and neil down the element I want to manipulate.

What I want to do is set the css class of an item according to
window.location (URL). But it doesn't work.

I call this function in
<body onload="SelectMenuItem();" >

here is the function
function SelectMenuItem() {
...
//i is a variable I set before.
var nodes_LI = document.getElementById("TopNav").childNodes;
for (j=0; j<nodes_LI.length; j++) {
nodes_LI[j].firstChild.removeAttribute("class");
It seems to me that you're trying to remove the attribute class
specification. You are not trying to remove the attribute node value.
}
nodes_LI[i].firstChild.setAttribute("class", "highlighted");


Why not then just use DOM 2 HTML method to do this?

if(nodes_LI[i].firstChild.nodeType == 1)
{
nodes_LI[i].firstChild.className ="highlighted";
//http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95362176
}
else
{
// code here
};

It's kinda difficult to offer you alternatives or guess better ones
since you have not provided any url nor a complete description of what
you were trying to do exactly.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.4 :)
Jul 23 '05 #2
fj

"DU" <dr*******@hotNOSPAMmail.com> wrote in message
news:3f************@uni-berlin.de...
fj wrote:
I have no problem nevigate and neil down the element I want to manipulate.
What I want to do is set the css class of an item according to
window.location (URL). But it doesn't work.

I call this function in
<body onload="SelectMenuItem();" >

here is the function
function SelectMenuItem() {
...
//i is a variable I set before.
var nodes_LI = document.getElementById("TopNav").childNodes;
for (j=0; j<nodes_LI.length; j++) {
nodes_LI[j].firstChild.removeAttribute("class");


It seems to me that you're trying to remove the attribute class
specification. You are not trying to remove the attribute node value.
}
nodes_LI[i].firstChild.setAttribute("class", "highlighted");


Why not then just use DOM 2 HTML method to do this?

if(nodes_LI[i].firstChild.nodeType == 1)
{
nodes_LI[i].firstChild.className ="highlighted";
//http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95362176
}
else
{
// code here
};

It's kinda difficult to offer you alternatives or guess better ones
since you have not provided any url nor a complete description of what
you were trying to do exactly.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.4 :)


Thank you. It's works fine now.

I was trying to set the current menu high-lighted by change it's css
class.Now I know I should use .className instead of .attribute.

Doesn't class="myCSSClass" look like an attribute of an element?

-fj
Jul 23 '05 #3

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

Similar topics

3
by: timmy_dale12 | last post by:
Hello , im a java programmer whos gotten tangled up in some javascripts. Im really stuck on this one can , can aybody explain this to me. I have a javscript which is to clone a table row and...
1
by: spaminator | last post by:
I have a script which adds a row. I am using the DOM model to do this. I have an image link which is to be inserted next to a input field in each row i add , how do i do this? I think i have to...
1
by: NewmanBT | last post by:
I'm trying to create a fairly simple form which contains a label, a button, and a textbox. I've done quite a bit of reading and, from what I can figure, the following should work, but isn't. ...
6
by: Pugi! | last post by:
I use mycurrent_cell.setAttribute("style", "background-color:green"); and mycurrent_cell.setAttribute("colspan", "3"); to set some attributes of a table. The code works perfect in FireFox and...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: ShutterMan | last post by:
I have a function that creates input buttons dynamically... function $NEW_BUTTON(id, content, parentId, cssclass, onclick) { var ctrl = document.createElement("input"); ctrl.id = id;...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.