473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.a sp">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.getEle mentsByTagName( "li").eleme nts
["leftnav1"].style.backgrou ndColor= '#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 2536
Invisible Man wrote:
Thanks for help in advance...

I'm trying to change the background of:

<li class="noflyout " name="leftnav1" ><a href="default.a sp">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.getEle mentsByTagName( "li").eleme nts
["leftnav1"].style.backgrou ndColor= '#cc0000'


getElementsByTa gName() 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.getEle mentById():

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

...

document.getEle mentById("leftn av1").style.bac kgroundColor='# 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.c om/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.getEl ementById ) {
var x = document.getEle mentById("leftn av1");
} else if (document.all ) {
var x = document.all["leftnav1"];
} else {
return
}

if ( x && x.style ) x.style.backgro undColor = '#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
2510
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> <div> <span>
7
2158
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
4092
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 <foo/>) From XHTML specification:
61
24504
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 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
5
5305
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 <div>s have a different background color. The side bar <div> extends partly down the page while the main content area <div> goes almost all the way down. The problem I am having is in getting the side bar's background to line up with the main...
3
3813
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" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
7
4611
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 for(x=0;x<this.document.elements.length;x++) { if(this.element.type= = "<DIV>") { this.element.z-index=1;
1
2439
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 invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
8
10047
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 editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.