Skip to content Skip to sidebar Skip to footer

How To Set Td Height To 0px In A Table?

I have an HTML table containing a few rows (this is built dynamically). All s have one inside. If one doesn’t have HTML content inside, I would li

Solution 1:

You can use the CSS pseudo selector :empty:

#myDynamicTabletd:empty
{
  display: none;
}

jsFiddle example: http://jsfiddle.net/vKEBY/6/

And if you want to support IE<9:

var ieVer = getInternetExplorerVersion();
if (ieVer != -1 && ieVer < 9.0) {
    // for IE<9 supportvar dynamicTable = document.getElementById("myDynamicTable");
    var TDs = dynamicTable.getElementsByTagName("td");

    for (var i = 0; i < TDs.length; i++) {
        if (TDs[i].innerHTML == "") {
            TDs[i].style.display = "none";
        }
    }
}

/**
  * All credits to Microsoft
  * http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx#ParsingUA
  */functiongetInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = newRegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
    }
    return rv;
}​

jsFiddle example: http://jsfiddle.net/vKEBY/6/

Solution 2:

If using jQuery this script could become much cleaner (just a thought).

$('#myTable td:empty').hide();

Post a Comment for "How To Set Td Height To 0px In A Table?"