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

Change Background on <div name=

Thanks for help in advance...

I'm trying to change the background of:

<li class="noflyout" name="leftnav1"><a href="default.asp">Home
</a></li>

CSS set it to blue - but want to us JS to change it to red if
the user lands on the page... I've got the following JS:

document.getElementsByTagName("li").elements
["leftnav1"].style.backgroundColor= '#cc0000'

Can anyone tell me what's wrong with it?

Regards

Lee

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #1
1 2524
Invisible Man wrote:
Thanks for help in advance...

I'm trying to change the background of:

<li class="noflyout" name="leftnav1"><a href="default.asp">Home
</a></li>

CSS set it to blue - but want to us JS to change it to red if
the user lands on the page... I've got the following JS:

document.getElementsByTagName("li").elements
["leftnav1"].style.backgroundColor= '#cc0000'


getElementsByTagName() returns a collection of all the elements in the
document with the tag name.

That is likely not the best approach here, it's better to replace NAME
attribute with an ID and use document.getElementById():

<li ... id="leftnav1">...</li>

...

document.getElementById("leftnav1").style.backgrou ndColor='#cc0000';

Read the group FAQ in regard to feature detection and incorporating
support for oder versions of IE with document.all.

<URL:http://www.jibbering.com/faq/#FAQ4_15>

Your statement should test that objects and methods are supported
before trying to use them and offer alternatives where appropriate:

if (document.getElementById ) {
var x = document.getElementById("leftnav1");
} else if (document.all ) {
var x = document.all["leftnav1"];
} else {
return
}

if ( x && x.style ) x.style.backgroundColor = '#cc0000';

If you intend using getElementById frequently, you may want to use
something like the DynWrite function mentioned at the above FAQ link.

--
Rob
Jul 23 '05 #2

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

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
7
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
5
by: Ben Gribaudo | last post by:
Hello! I am working on revising my Web site template. The main part of the page is divided into two columns (each a <div>)--a side bar on the left and the main content area on the right. Both...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
7
by: News | last post by:
I would like to know how I loop through a html file and validate it is the type of element I am seeking and then change something in the element. IE ...
1
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is...
8
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.