Reputation: 1042
I have the following line on my page in the $(document).ready(function(){...}
It is done in ASP.NET
$("#standard-styling").html($("#standard-styling").text().replace(/([^\s-]{5})(?=[^\s-])/g, '$1­'));
HTML:
<div id="standard-styling" class="description">
<% Response.Write(Model.Description); %>
</div>
It works great for splitting long words onto multiple lines by adding a -<br>
if the browser thinks it's necessary, and ignoring it if not (http://www.quirksmode.org/oddsandends/wbr.html). However, if the description contains a link, then the link will not show up as a hyperlink. Also, if there are line breaks, <br />
or other tags, they are likely to be broken and ignored as well. lastly, it is causing problems with encoded characters like <br />
. It is then seen as <br />
and does insert a line break there.
Is there a better way to go about this?
Upvotes: 2
Views: 5004
Reputation: 5769
Use css:
#standard-styling {
word-wrap: break-word;
}
Or using jQuery:
$("#standard-styling").css('word-wrap', 'break-word');
UPD:
jQuery Example: http://jsbin.com/ojoges/1/
CSS Example: http://jsbin.com/ojoges/
Upvotes: 1