Results 1 to 3 of 3

Thread: css/javascript class

  1. #1
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default css/javascript class

    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    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:

    Code:
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •