How can i find out the size of a cell with javascript

后端 未结 4 887
盖世英雄少女心
盖世英雄少女心 2021-01-28 19:06

I have a popup that pops up right underneathe a so it looks like the (don\'t ask why). on 1024 *760 its the same width as the tab

相关标签:
4条回答
  • 2021-01-28 19:21
    var element = document.getElementById('whatever');
    //or however you want to get the element
    var width;
    if (typeof element.clip !== "undefined") { width = element.clip.width; } 
    else {
        if (element.style.pixelWidth) { width = element.style.pixelWidth; } 
        else { width = element.offsetWidth; } 
    } 
    
    0 讨论(0)
  • 2021-01-28 19:21

    jQuery is ideal if you can use it.

    $('#popupId').width( $('#cellID').width() );
    

    or you might need to use outerWidth(), depending on your needs.

    0 讨论(0)
  • 2021-01-28 19:22

    try this ... let me know if it helps

    Col Header one Col Header two abc xyz
    <script language="javascript" type="text/javascript" >
        $(document).ready(function () {
            var tableWidth = $('#testTable').outerWidth();
            var thOneWidth = $('#testTable th.#one').outerWidth();
            var thTwoWidth = $('#testTable th.#two').outerWidth();
    
            alert('Table width : ' + tableWidth + ' \n' + 'Table Col One width : ' + thOneWidth + ' \n' + 'Table Col Two width : ' + thTwoWidth + ' \n');
        });
    </script>
    
    0 讨论(0)
  • 2021-01-28 19:23

    With jQuery, you could use $('td').outerWidth(); You would likely need to add a class to the TD element in order to specify it with your jQuery selector. By the way, this jQuery method uses the outerWidth property "baked in" to JS, but jQuery is easier :)

    0 讨论(0)
提交回复
热议问题