Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

limiting the length of dynamic text inside html element

function truncateText(selector, maxLength) {
    var element = document.querySelector(selector),
        truncated = element.innerText;

    if (truncated.length > maxLength) {
        truncated = truncated.substr(0,maxLength) + '...';
    }
    return truncated;
}
//You can then call the function with something like what i have below.
document.querySelector('p').innerText = truncateText('p', 107);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #limiting #length #dynamic #text #html #element
ADD COMMENT
Topic
Name
6+6 =