Search code examples
tablesorter

How to combine these 2 small tablesorter scripts


I have a jquery tablesorter script, and I am trying to add these two functions together. It seems like it would be simple, though unfortunately I have very little knowledge with javascript.

It will only work when I have one or the other in the , not like i have it below.

<script type="text/javascript">
$(document).ready(function(){
    $(function() {
        $("table").tablesorter({ sortList:[[0,0]]
    }); }); });
$(document).ready(function(){
         $("table").tablesorter({
            textExtraction:function(s){
            if($(s).find('img').length == 0) return $(s).text();
            return $(s).find('img').attr('alt');
            } 
      });
});
</script>

Solution

  • Try to do:

    <script type="text/javascript">
    $(document).ready(function () {
        $("table").tablesorter({
            sortList: [
                [0, 0]
            ],
            textExtraction: function (s) {
                if ($(s).find('img').length == 0) return $(s).text();
                return $(s).find('img').attr('alt');
            }
        });
    });
    </script>