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

apply multiple classes

it is possible by dom(scripting) to apply multiple classes to the
className attribute.
elmRef.className = 'Class1 Class2 ...' ;

but what if some other script assigns its own classes. in this case, it
would be possible to track our classes in the className attribute(by
searching in the string) and remove or add them accordingly but aren't
there any flexible approach? it would be better if className is a
collection that we could determine easily if required classes are
applied or not.
or is there any different/better approach to apply our multiple classes
without depending on other scripts on the page?

thanks

Aug 5 '06 #1
2 5272
Only thing I can think of is to write your own JS functions for
handling reading back and adding to className, splitting an array on
the 'space' character should start you off. I can imagine someone must
have written one already.. anyone?

Good luck
Den
spolsky wrote:
it is possible by dom(scripting) to apply multiple classes to the
className attribute.
elmRef.className = 'Class1 Class2 ...' ;

but what if some other script assigns its own classes. in this case, it
would be possible to track our classes in the className attribute(by
searching in the string) and remove or add them accordingly but aren't
there any flexible approach? it would be better if className is a
collection that we could determine easily if required classes are
applied or not.
or is there any different/better approach to apply our multiple classes
without depending on other scripts on the page?

thanks
Aug 7 '06 #2
spolsky wrote:
it is possible by dom(scripting) to apply multiple classes to the
className attribute.
elmRef.className = 'Class1 Class2 ...' ;

but what if some other script assigns its own classes. in this case, it
would be possible to track our classes in the className attribute(by
searching in the string) and remove or add them accordingly but aren't
there any flexible approach? it would be better if className is a
collection that we could determine easily if required classes are
applied or not.
Untested code:

function hasClassName(str, className)
{
var strPadded = " " + str + " ";
var classNamePadded = " " + className + " ";
return strPadded.indexOf(classNamePadded) != -1;
}

function removeClassName(element, className)
{
var strPadded = " " + element.className + " ";
var classNamePadded = " " + className + " ";
var result = strPadded.replace(classNamePadded, "");
result = result.substring(1, result.length - 1);
element.className = result;
}

function addClassName(element, className)
{
var str = element.className;
if (!hasClassName(str, className))
{
str += " ";
str += className;
element.className = str;
}
}
?
or is there any different/better approach to apply our multiple classes
without depending on other scripts on the page?

thanks
Aug 7 '06 #3

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

Similar topics

20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
8
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods,...
3
by: spolsky | last post by:
hi, it is possible to apply multiple styles as shown in the following example. <STYLE TYPE="text/css"><!-- BODY { background-color:salmon; } P { margin-left:20px; } .clsCode {...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
15
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
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: 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
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
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
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...
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.