473,803 Members | 3,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using the DOM to change the CLASS attribute

hello. i have a <tablewith each cell having its own unique ID (see
below). What i want to do is change the CLASS attribute for the SPAN
in one of the cells. i'm currently testing this in IE 6. In my
javascript, i wrote

document.getEle mentById('0_1') .getElementsByT agName("span")[0].setAttribute(" className",
"hasEvents" );

However, i get the following error message:

'document.getEl ementById(...). getElementsByTa gName(...).0' is null or
not an object.

Can someone please help? thanks

HTML code:

<table>
<tr>
<td id="0_0"><span class="noEvents ">1</span></td>
<td id="0_1"><span class="noEvents ">2</span></td>
<td id="0_2"><span class="noEvents ">3</span></td>
</tr>
</table>

Sep 21 '06 #1
6 9281
document.getEle mentById('YO'). getElementsByTa gName("span")[0].className
= "hasEvents" ;
silly putty wrote:
hello. i have a <tablewith each cell having its own unique ID (see
below). What i want to do is change the CLASS attribute for the SPAN
in one of the cells. i'm currently testing this in IE 6. In my
javascript, i wrote

document.getEle mentById('0_1') .getElementsByT agName("span")[0].setAttribute(" className",
"hasEvents" );

However, i get the following error message:

'document.getEl ementById(...). getElementsByTa gName(...).0' is null or
not an object.

Can someone please help? thanks

HTML code:

<table>
<tr>
<td id="0_0"><span class="noEvents ">1</span></td>
<td id="0_1"><span class="noEvents ">2</span></td>
<td id="0_2"><span class="noEvents ">3</span></td>
</tr>
</table>
Sep 21 '06 #2
didn't work

ni*********@gma il.com wrote:
document.getEle mentById('YO'). getElementsByTa gName("span")[0].className
= "hasEvents" ;
silly putty wrote:
hello. i have a <tablewith each cell having its own unique ID (see
below). What i want to do is change the CLASS attribute for the SPAN
in one of the cells. i'm currently testing this in IE 6. In my
javascript, i wrote

document.getEle mentById('0_1') .getElementsByT agName("span")[0].setAttribute(" className",
"hasEvents" );

However, i get the following error message:

'document.getEl ementById(...). getElementsByTa gName(...).0' is null or
not an object.

Can someone please help? thanks

HTML code:

<table>
<tr>
<td id="0_0"><span class="noEvents ">1</span></td>
<td id="0_1"><span class="noEvents ">2</span></td>
<td id="0_2"><span class="noEvents ">3</span></td>
</tr>
</table>
Sep 21 '06 #3
did you change the id of the TD to "YO"

silly putty wrote:
didn't work

ni*********@gma il.com wrote:
document.getEle mentById('YO'). getElementsByTa gName("span")[0].className
= "hasEvents" ;
silly putty wrote:
hello. i have a <tablewith each cell having its own unique ID (see
below). What i want to do is change the CLASS attribute for the SPAN
in one of the cells. i'm currently testing this in IE 6. In my
javascript, i wrote
>
document.getEle mentById('0_1') .getElementsByT agName("span")[0].setAttribute(" className",
"hasEvents" );
>
However, i get the following error message:
>
'document.getEl ementById(...). getElementsByTa gName(...).0' is null or
not an object.
>
Can someone please help? thanks
>
HTML code:
>
<table>
<tr>
<td id="0_0"><span class="noEvents ">1</span></td>
<td id="0_1"><span class="noEvents ">2</span></td>
<td id="0_2"><span class="noEvents ">3</span></td>
</tr>
</table>
Sep 21 '06 #4
silly putty wrote:
didn't work
Could you be any more vague?
>>document.getE lementById('0_1 ').getElementsB yTagName("span" )[0].setAttribute(" className",
"hasEvents" );
An ID attribute value cannot start with a digit. Your ID is invalid, so
results of the getElementById( ) call are unpredictable.

One way of debugging your own problem is to do an alert at each stage to see
where your problem is happening:

alert(document. getElementById( '0_1'));
alert(document. getElementById( '0_1').getEleme ntsByTagName("s pan"));
alert(document. getElementById( '0_1').getEleme ntsByTagName("s pan")[0]);

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 21 '06 #5
Matt was right in that the ID can't begin with a digit. Thanks Matt
for figuring out the problem.

Just curious, ni*********@gma il.com suggested that I change the ID to
Y0. what does Y0 mean? Thanks
Matt Kruse wrote:
silly putty wrote:
didn't work

Could you be any more vague?
>document.getEl ementById('0_1' ).getElementsBy TagName("span")[0].setAttribute(" className",
"hasEvents") ;

An ID attribute value cannot start with a digit. Your ID is invalid, so
results of the getElementById( ) call are unpredictable.

One way of debugging your own problem is to do an alert at each stage to see
where your problem is happening:

alert(document. getElementById( '0_1'));
alert(document. getElementById( '0_1').getEleme ntsByTagName("s pan"));
alert(document. getElementById( '0_1').getEleme ntsByTagName("s pan")[0]);

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 21 '06 #6
silly putty wrote:
Matt was right in that the ID can't begin with a digit. Thanks Matt
for figuring out the problem.
Please don't top-post here, reply below a trimmed quote of whatever you
are replying to.
>
Just curious, ni*********@gma il.com suggested that I change the ID to
Y0. what does Y0 mean?
Nothing, it just means your ID doesn't start with a digit.

Incidentally, since you are looking for spans within the table, have
you consdered using an ID on the table and just getting all the spans
once? If you base the function on just getting an element reference,
you can re-use the code for any kind of element.

e.g.

<table id="theTable">
<tr>
<td><span class="noEvents ">...</span>.
<td><span class="hasEvent s">...</span>
<td><span class="noEvents ">...</span>
</tr>
</table>

<script type="text/javascript">
function doSpanStuff(el) {
var allSpans = el.getElementsB yTagName('span' );
var i = allSpans.length ;
var aSpan;
while (i--){
aSpan = allSpans[i];
if ('hasEvents' == aSpan.className ){
/* do stuff */
}
}
}

doSpanStuff(doc ument.getElemen tById('theTable '));

</script>
--
Rob

Sep 22 '06 #7

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

Similar topics

1
6826
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
2
4425
by: Varun Singal | last post by:
Hi I am calling .NET components from my Classical ASPs. For this I strong named my assemblies, then registered them in the resistry ( using RegAsm), and put them in GAC (using GacUtil) . Everything worked fine and my ASPs were able to call and use them. The problem comes when my ASP code assigns an ASP object variable to a property of a class in the assembly like: oDotNetObject("Name") = Request("Name")
0
1066
by: Jeff User | last post by:
Here is what I have and what I would like to do: I am building a web client application. I add a web reference to some web service server to my project so that now I can call the web service. A proxy class is generated for me. This is nice. It works! Now, the method that is generated in the proxy class has an attribute preceding it that, among other things, contains the web address of the web service and the particular method at that...
2
2386
by: Zach Mortensen | last post by:
I can't seem to get dynamically-compiled JScript code to use C#-defined custom attributes. I have a simple attribute and a class defined in a C# assembly: namespace MyNamespace { public abstract class MyCsharpAttribute : Attribute { }
2
2135
by: Jeff User | last post by:
Here is what I have and what I would like to do: I am building a web client application. I add a web reference to some web service server to my project so that now I can call the web service. A proxy class is generated for me. This is nice. It works! Now, the method that is generated in the proxy class has an attribute preceding it that, among other things, contains the web address of the web service and the particular method at that...
3
3203
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what the set piece of the Name property gets compiled to, which I am getting from the stack trace, then the attributes are not returned. For example, Class Person has a property called "Name" which has a custom attribute decorating it. Inside the set...
0
6616
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the stream. XML serialization serializes only the public fields and property values of an object...
2
8763
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not need anything other than the *.dll, but at the moment I am just trying to get any of the overloads...
5
7103
by: MATTXtwo | last post by:
I have surf throught many site and found this... http://www.adobe.com/go/gn_home how to change an element attribute to other class attribute... I wonder......can we change class attribute to something else.. i need to change class that have.DisplayBlock { display : block; } CODE] to .DisplayNone { display: none; }
15
1795
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo(): bar = 1 gum = 2
0
9703
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
9566
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10300
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
9127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7607
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
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...
1
4277
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
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
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.