javascript - How to find whether text in a text area is wrapped to multiple lines? -


how can find whether long text in textarea wrapped 2 or more lines?

i'm not talking new line chars discussed here.

i'm aware of plugin textarea line count

any simpler method?

i experimented on , came hack involves following:

  1. disabling text-wrapping in textarea (plus disable padding)

  2. checking if textarea's scrollwidth greater it's width.

the basic logic used if text spanning multiple lines, means when wrapping turned off, should horizontal scrollbar.

demo: http://jsfiddle.net/fng3d/

disclaimer: code below result of 10 minute fiddle, not production quality

function checkmulti(id) {     var ta = $('#'+id), multi = false;      // disable wrapping, padding , enable horiz scoll     ta.addclass('nowrap');      // check if there scrolled horizontally (means multi-lines otherwise)     multi = ( ta[0].scrollwidth > ta.width() );      // checking done. remove class.     ta.removeclass('nowrap');      alert('spread on multiple-lines: ' + multi); }  /* nowrap class */ .nowrap {     overflow-x: scroll;     white-space: nowrap;     padding: 0; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -