jquery - Calculating text width -


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

So, here's the code:

  var c = $ ('. Calltoaction'); Var cTxt = c.text (); Var cWidth = cTxt.outerWidth (); C.css ('width', cWidth);  

This works better for me:

  $ .fn.textWidth = function () {var html_org = $ (this) .html (); Var html_calc = '& lt; Span & gt; ' + Html_org + '& lt; / Span & gt; '; $ (This) .html (html_calc); Var width = $ (this). Find ('span: first'). Width (); $ (This) .html (html_org); Return width; };  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -