PDA

View Full Version : css/javascript class



JeremyS
09-20-2005, 01:27 PM
Is it possible to put two classes to one table? I have a table that I have the css file to, in the .css file its 'tableIc' ( <table class='tableic' ). That's for the style of it. Now the javascript, is to make the table sortable. It's class is 'sortable ( <table class='sortable' ). I need both of them in the same table, for the style, and to make it sortable. Is this possible? If so, how?

Sorry if I didn't make it very clear.

Twey
09-20-2005, 03:02 PM
It's possible to use multiple classes seperated by spaces. However, I'm not sure how some browsers might react to this.
My best suggestion is to use an id instead of a class for the sorting script. If you don't know how to do this, post your code here (or link to it) and I'll have a look.

mwinter
09-21-2005, 02:07 PM
It's possible to use multiple classes seperated by spaces. However, I'm not sure how some browsers might react to this.Any modern browser should handle it fine. IE 4 and NN 4 will ignore all classes specified in this way, but most CSS needs to be hidden entirely from these two anyway due to their woeful support.


My best suggestion is to use an id instead of a class for the sorting script.But if there was more than one sortable table?


To the OP: Clearly, you can't use an equality operator to test if the table is to be sortable if it can contain more than one class name. Instead, you should use a regular expression. For example:


function ofClass(element, className) {
return (new RegExp('(^|\\s+)' + className + '(\\s+|$)')).test(element.className);
}

if(ofClass(myTable, 'sortable')) {
/* ... */
}where myTable is a reference to the table element (obtained via the document.getElementById method, perhaps).

Mike