I am trying to measure the length of text (based on this: Calculating text width) and then slice it at a certain point.
Here's my code, what am I missing?
$(document).ready(function() {
$.fn.textWidth = function() {
var html_org = $(this).html();
var html_calc = "<span>" + html_org + "</span>"
$(this).html(html_calc);
var width = $(this).find("span:first").width();
$(this).html(html_org);
return width;
};
function sliceTxt() {
var w = $(".limitBox").textWidth() * 2,
textArray = $(".limitBox").text().split(""),
ellipsedText = textArray.slice(0, w - 3).join("") + "...";
}
sliceTxt();
});