Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert nested json to query string 
Javascript :: clear contents of dependent drop down list automatically javascript stack overflow 
Javascript :: store string in array javascript 
Javascript :: destructuring interfaces in the most simple way <<Java Script 
Javascript :: jboss-ejb-client.propeties exampe de configuration 
Javascript :: hash decrypt md5 
Javascript :: undefined ext in fn.dataTable.ext.search.push 
Javascript :: numbers Math 
Javascript :: facade js 
Javascript :: undo pwa 
Javascript :: change string to object in html 
Javascript :: reduceat 
Javascript :: jquery excel export 
Javascript :: nestjs openapi yaml file 
Javascript :: jq add variable 
Javascript :: Lodash Cypress for each function 
Javascript :: Conditionally add members to an object 
Javascript :: how to empty nodeList 
Javascript :: sw.js 
Javascript :: different way to for loop js 
Javascript :: javascript replace url on sentence as achor 
Javascript :: Nodemailer Reuseable Code 1 
Javascript :: mongoose connecting directly rather than tunnel 
Javascript :: Scroll event throttling JS MDN 
Javascript :: js to es6 convertor 
Javascript :: Here is an example of loading a series of middleware functions at a mount point, with a mount path. It illustrates a middleware sub-stack that prints request info for any type of HTTP request to the /user/:id path. 
Javascript :: nyaapi node 
Javascript :: typeorm caching queries time limit by id 
Javascript :: js set array relation 
Javascript :: date change 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =