JQuery table offsetWidth question

I studied this for several hours and cannot understand.

I am trying to write code to align table headers and table columns.
I am trying to figure out the total width of the header cell and the width of the column.

but for some strange reason it tdOffsetgets the value, and thOffset- NaN.

$("#tblTasks tbody tr:eq(0) td").each(function(index)
{
    tdOffset = parseInt(this.offsetWidth);

    thEl = $('#tblTasks thead tr:eq(0) th:eq(' + index.toString() + ')').first();
    thOffset = parseInt(thEl.offsetWidth);

    alert('tdOffSet' + tdOffset + ' thOffset:' + thOffset);
}

Can someone point out what I'm doing wrong?

Thank you and be happy.

+5
source share
1 answer

The reason it this.offsetWidthworks thEl.offsetWidthdoes not mean that it thisrefers to a DOM element, but thElrefers to a jQuery object.

DOM "" thOffset,

thEl[0].offsetWidth
+7

All Articles