Calculating text width

后端 未结 22 1374
轻奢々
轻奢々 2020-11-22 03:36

I\'m trying to calculate text width using jQuery. I\'m not sure what, but I am definitely doing something wrong.

So, here is the code:

var c = $(\'.c         


        
22条回答
  •  太阳男子
    2020-11-22 04:02

    Call getColumnWidth() to get the with of the text. This works perfectly fine.

    someFile.css
    .columnClass { 
        font-family: Verdana;
        font-size: 11px;
        font-weight: normal;
    }
    
    
    function getColumnWidth(columnClass,text) { 
        tempSpan = $('')
              .appendTo($('body'));
        columnWidth = tempSpan.width();
        tempSpan.remove();
    return columnWidth;
    }
    

    Note:- If you want inline .css pass the font-details in style only.

提交回复
热议问题