473,395 Members | 1,791 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,395 software developers and data experts.

How to set the class attribute?

Hello,

On this way I set the target attribute for a hyperlink.

var the_link = sel.parentElement();
the_link.target = '_blank';

Now I also want to set the class attribute.
When I use the word class I get errors.

Can somebody tell me how to set the class attribute?

Thanks!
Jul 23 '05 #1
7 6626
Arjen wrote:
Hello,

On this way I set the target attribute for a hyperlink.

var the_link = sel.parentElement();
the_link.target = '_blank';

Now I also want to set the class attribute.
When I use the word class I get errors.

Can somebody tell me how to set the class attribute?

Thanks!


className

Mick
Jul 23 '05 #2
"Mick White" <mw******@BOGUSrochester.rr.com> schreef in bericht
news:wI*********************@twister.nyroc.rr.com. ..
Arjen wrote:
Hello,

On this way I set the target attribute for a hyperlink.

var the_link = sel.parentElement();
the_link.target = '_blank';

Now I also want to set the class attribute.
When I use the word class I get errors.

Can somebody tell me how to set the class attribute?

Thanks!


className

Mick


Mick,

Then it adds classname as attributename... but it must be class.
If tried to run your solution and it doesn't work... other options?

Thanks.

Jul 23 '05 #3
Arjen wrote:
> Can somebody tell me how to set the class attribute?
className
Then it adds classname as attributename...
Not if you do it right.
but it must be class.
class is a reserved keyword in ECMAScript, so className is used instead.
If tried to run your solution and it doesn't work... other options?


Present us with a URL so we can see the code you tried to use. Then we might
be able to tell why it isn't working.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Jul 23 '05 #4
"Arjen" <bo*****@hotmail.com> writes:
className
Then it adds classname as attributename...
No. The HTML attribute is called "class". The corresponding DOM
property is called "className".
but it must be class. If tried to run your solution and it doesn't
work... other options?


Try it again, it is correct:
---
<style type="text/css">
.foo {color:red;background:yellow;}
.bar {color:yellow;background:red;}
</style>
<div class="foo" onclick="this.className='bar'">CLICK</div>
---

//L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5

"David Dorward" <do*****@yahoo.com> schreef in bericht
news:c8*******************@news.demon.co.uk...
Arjen wrote:
> Can somebody tell me how to set the class attribute? className
Then it adds classname as attributename...


Not if you do it right.
but it must be class.


class is a reserved keyword in ECMAScript, so className is used instead.
If tried to run your solution and it doesn't work... other options?


Present us with a URL so we can see the code you tried to use. Then we

might be able to tell why it isn't working.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>


Here it is:
var the_link = sel.parentElement();
the_link.target = '_blank';
the_link.classname = 'DCELink';

Thanks!
Jul 23 '05 #6
"Arjen" <bo*****@hotmail.com> writes:
the_link.classname = 'DCELink';


Javascript is case sensitive. It should be
the_link.className = 'DCELink';

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #7

"Lasse Reichstein Nielsen" <lr*@hotpop.com> schreef in bericht
news:br**********@hotpop.com...
"Arjen" <bo*****@hotmail.com> writes:
the_link.classname = 'DCELink';
Javascript is case sensitive. It should be
the_link.className = 'DCELink';

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'


Okay, thanks! ;-)
Jul 23 '05 #8

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
3
by: George Sakkis | last post by:
I'm trying to write a decorator similar to property, with the difference that it applies to the defining class (and its subclasses) instead of its instances. This would provide, among others, a way...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
2
by: Ewald R. de Wit | last post by:
I'm running into a something unexpected for a new-style class that has both a class attribute and __slots__ defined. If the name of the class attribute also exists in __slots__, Python throws an...
0
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms...
5
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace...
5
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable...
3
by: antred | last post by:
Hello everyone, While working on a program I encountered a situation where I'd construct a largish data structure (a tree) from parsing a host of files and would end up having to throw away...
1
by: chris.bahns | last post by:
Hello All, I am fairly new to creating custom attributes, and want to get a better feel for how they should be named. We have a class hierarchy, with a base class called "SequenceCommand". This...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
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
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
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...
0
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,...

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.