开发者

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

I have a popup that pops up right underneathe a <th> so it looks like the <td> (don't ask why). on 1024 *760 its the same width as the table header cell, but on 1280 it's not as wide. How can i wirte a script to find out the width of my <th>? (I'm using jQuery.)

edit:

<th id="telephoneTH" width="25%" >
<span  id="telephoneSpan" class="headerShortDetails">Telephone</span><span onclick="showContactPopup();"  class="infoSpans"> ${bean.phoneNumber}</span>
</th>


var width2 = $('#telephoneTH').outerWidth();开发者_开发技巧
alert(width2);

error: 'null' is null or not an object


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 :)


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; } 
} 


jQuery is ideal if you can use it.

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

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜