473,748 Members | 11,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

apply multiple classes

it is possible by dom(scripting) to apply multiple classes to the
className attribute.
elmRef.classNam e = '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 5286
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.classNam e = '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.classNam e = '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(st r, className)
{
var strPadded = " " + str + " ";
var classNamePadded = " " + className + " ";
return strPadded.index Of(classNamePad ded) != -1;
}

function removeClassName (element, className)
{
var strPadded = " " + element.classNa me + " ";
var classNamePadded = " " + className + " ";
var result = strPadded.repla ce(classNamePad ded, "");
result = result.substrin g(1, result.length - 1);
element.classNa me = result;
}

function addClassName(el ement, className)
{
var str = element.classNa me;
if (!hasClassName( str, className))
{
str += " ";
str += className;
element.classNa me = 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
10082
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 advance for enlightment ... here's the snippet #!/usr/bin/python
22
23383
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 examples?
8
2209
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, A1+X2, A2+X1 and A2+X2: interface A class A1 implements A
3
2041
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 { font-family:"Comic Sans MS"; font-size:10pt; color:navy;}
6
3990
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 string UID; public string PWD; }
15
28373
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 an error saying you are not allowed Multiple base classes. /// <summary>
47
4024
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 support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple base classes. This supports the above quote. However, under the "CodeClass2.Bases" property (part...
2
2585
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). -- Paul for cls in (A,B,C,D): seen = set()
2
2097
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 from one base class are inherited into two derived classes. You want both derived classes to share member variables of the one base class. You can do this way so you don't need keyword -- friend. You can add virtual public One_Base_Class on...
0
8989
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
8828
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,...
0
9537
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...
1
9319
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,...
1
6795
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
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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
3309
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
2213
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.