tags:

views:

46

answers:

3

I am using Stupid Fixed Header to fix the headers of two tables. For that i am using following script.

$(document).ready(function(){    
    $("#table1").fixedHeader({
     height: 160,
     adjustWidth: function(th){
     if($.browser.msie){
      return $(th).width()+10;
     }
      return $(th).width();
     }
    });

    $("#table2").fixedHeader({
     height: 160,
     adjustWidth: function(th){
     if($.browser.msie){
      return $(th).width()+10;
     }
      return $(th).width();
     }
    });
})

Now the point is, i am writing the same code twice. Once for table1 and then for table2. Is it possible to write it only once?

+2  A: 

Use a class selector instead of id selector. Something like

$(".tablefidedheaders").fixedHeader({
        height: 160,
        adjustWidth: function(th){
        if($.browser.msie){
                return $(th).width()+10;
        }
                return $(th).width();
        }
    });

Give the class name [tablefidedheaders] for the two tables.

rahul
+5  A: 
$("#table1, #table2").fixedHeader ...
Darin Dimitrov
great it worked
Rakesh Juyal
+1  A: 

As adamantium said, selecting by class is probably a better practice. If you want to select by multiple ids, you can do this:

$(document).ready(function(){           
    $("#table1, #table2").fixedHeader({
        height: 160,
        adjustWidth: function(th){
        if($.browser.msie){
                return $(th).width()+10;
        }
                return $(th).width();
        }
    });
micahwittman