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

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -