Function this parameter on onclick
<p>I've some html code generated in javascript like this</p>

<pre><code>cell.innerHTML = '&lt;a href="#" class="sortheader" id="sortheader_'+i+'" '+ 
        'onclick="ts_resortTable(this, '+i+');return false;"&gt;' + 
        txt+'&lt;span class="sortarrow"&gt;&lt;/span&gt;&lt;/a&gt;';
</code></pre>

<p>I'd like to call the function ts_resortTable() but independently of the onclick event how can i generate the "this" parameter of the function?</p>

<p>I try to do this</p>

<pre><code>ts_resortTable.call(document.getElementById('sortheader_'+i), i);
</code></pre>

<p>and this</p>

<pre><code>ts_resortTable(document.getElementById('sortheader_'+i), i);
</code></pre>

<p>But it's not working</p>

<p>The function that i'm trying to call is this:</p>

<pre><code>function ts_resortTable(lnk,clid) {

    //save clid in cookies
    $.cookie("clid", clid);

    //fade to table
    $('#table8k6k_progress').before('&lt;div id="loading" style="background: #fff; position: absolute; margin-top: -25px; padding: 3px 5px; font-weight: bold;"&gt;Loading...&lt;/div&gt;');
    $('#table8k6k_progress').fadeTo('fast',0.5, function() {
        TIMERSTART = (new Date()).getTime();
        // get the span
        var span;
        for (var ci=0;ci&lt;lnk.childNodes.length;ci++) {
            if (lnk.childNodes[ci].tagName &amp;&amp; lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
        }
        var spantext = ts_getInnerText(span);
        var td = lnk.parentNode;
        var column = clid || td.cellIndex;
        var table = getParent(td,'TABLE');

        // Work out a type for the column
        if (table.rows.length &lt;= 1) return;
        var itm = ts_getInnerText(table.rows[1].cells[column]);
        //itm = itm.substr(0,7);
        sortfn = ts_sort_caseinsensitive;
        if (itm.match(/^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}\s\d\d\W\d\d$/)) sortfn = ts_sort_date;
        if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
        if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
        if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
        if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
        SORT_COLUMN_INDEX = column;
        var firstRow = new Array();
        var newRows = new Array();
        for (i=0;i&lt;table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
        for (j=1;j&lt;table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

        newRows.sort(sortfn);

        if (span.getAttribute("sortdir") == 'down') {
            ARROW = stIsIE ? '&amp;nbsp&lt;font face="webdings"&gt;6&lt;/font&gt;' : '&amp;nbsp;&amp;#x25BE;';
            newRows.reverse();
            span.setAttribute('sortdir','up');
        } else {
            ARROW = stIsIE ? '&amp;nbsp&lt;font face="webdings"&gt;5&lt;/font&gt;' : '&amp;nbsp;&amp;#x25B4;';
            span.setAttribute('sortdir','down');
        }

        // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
        // don't do sortbottom rows
        for (i=0;i&lt;newRows.length;i++) { if (!newRows[i].className || (newRows[i].className &amp;&amp; (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
        // do sortbottom rows only
        for (i=0;i&lt;newRows.length;i++) { if (newRows[i].className &amp;&amp; (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}

        // Delete any other arrows there may be showing
        var allspans = document.getElementsByTagName("span");
        for (var ci=0;ci&lt;allspans.length;ci++) {
            if (allspans[ci].className == 'sortarrow') {
                if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                    allspans[ci].innerHTML = '';
                }
            }
        }

        span.innerHTML = ARROW;

        //fadeTo
        $('#table8k6k_progress').fadeTo('fast', 1);

        //remove div loading
        $('#loading').remove();
    });


    //alert("Time taken: " + ( (new Date()).getTime() - TIMERSTART ) + "ms");

}
</code></pre>
