I'm trying to implement a requirement that requires I set a maximum line length for the contents of a div element. But when I open the page in Firefox, I get an error about a "long-running script" and am asked to Continue, Debug, or Stop Script. I don't understand why this is happening. This is my code:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$.fn.lineCount = function () {
var lineHeight = this.css("line-height"); // returns "Xpx"
return document.getElementById(this.attr("id")).offsetHeight / parseInt(lineHeight.substr(0, lineHeight.length - 2));
};
$.fn.truncateLineCount = function (countAfterTruncation) {
while (this.lineCount() > countAfterTruncation) {
var text = this.html();
this.html(text.substr(0, text.length - 1) + "…");
}
};
$(function () {
$("#title").truncateLineCount(3);
});
</script>
</head>
<body>
<div id="title">
My MVC Application<br />
steaks<br />
are<br />
awesome
</div>
</body>
</html>
What gives?