I have a table with different values. First column contains labels. I need to get the width of the widest label. I assume I need some sort of a loop, but then what?
$("#myTable td:nth-child(1)").width();
Thanks.
var w = 0;
$("#myTable tr td:first").each(function(){
if($(this).width() > w){
w = $(this).width();
}
});
I assume that you have one <label>
element inside all <td>
elements in the first column (since it makes no sense to compare the widths of the <td>
elements themselves — within the same column they are equally wide (not considering colspan != 1
)):
var widestLabel = 0;
$("#myTable td:nth-child(1) label").each(function() {
widestLabel = Math.max(widestLabel, $(this).width());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With