I am looking for a way to add together table cell widths for one row. So, if I add a cell to a row of one table with a specified width, that new sum can be retrieved. Any suggestions are appreciated!
@bubbisthedogauthorOct 18.2005 — #Thanks for the suggestion, Lerura! That's what I'll do. I was curious though: Could you give the table an id, and then use the 'length' method in a loop to get each cell's width (as opposed to having to do a getElementById() for each cell's id)? Forgive me for being ambiguous; I'm obviously new when it comes to JavaScript.
Thanks again for the suggestion and taking the time to respond. ?
@KorOct 19.2005 — #Thanks for the suggestion, Lerura! That's what I'll do. I was curious though: Could you give the table an id, and then use the 'length' method in a loop to get each cell's width (as opposed to having to do a getElementById() for each cell's id)? Forgive me for being ambiguous; I'm obviously new when it comes to JavaScript.
Thanks again for the suggestion and taking the time to respond. ?
Regards,
bubbis[/QUOTE]
[B]offsetWidth[/B] and [B]getElementsByTagName()[/B] will do the job
var myCells = document.getElementById('mytable').getElementsByTagName('td');
for(var i=0;i<myCells.length;i++){
alert('the cell no '+i+' has width= '+myCells[i].offsetWidth+' px')
}
But if you want only to know which is the width of the table after a new cell was added,simply
var tabWidth = getElementById('mytable').offsetWidth;
caution, as offsetWidth is a readonly attribute, the returned value is a [B]number[/B]!
@bubbisthedogauthorOct 19.2005 — #Lerura, Kor: [B]THANK YOU[/B] . ? Both suggestions will not only prove very useful for me, but have also expanded my knowledge of how JavaScript works. Thanks again to both of you for providing your insight and taking the time to respond to my query.