Wrap continuous string or text in javascript

Many times it is required to split a long continuous string or text basis of the width of the element in pixels. I had found a good solution on web and redesigned it to make it generic and cross-browser compatible.

You just require to call this javascript function

wrapText text , lengthInPixels , splitter ) 

Following is the usage of the function

<script language=”javascript” src=”wrapText.js”></script>
<input id=”txt” size=”150″ /><input type=”button” onclick=”document.getElementById(‘lbl’).innerHTML=wrapText ( document.getElementById(‘txt’).value , 200 , <br/>’ );” value=”Wrap Text” />

<div id=”lbl”></div>

  [download id=”4″]


Reblog this post [with Zemanta]

Leave a Reply