jQuery set fixed length content in div

Rate this post

i m stuck into one situation, i have a div having some paragraph content. i only want to show 100 words of content in div for example – (sometextjonty) i only want to show 7 alphabets content in div so my div now will show (sometex) text upto here . i only want to do with jquery not with css, any solutions for this. I have no any clue how to do that

echo'<div class="content textlimit"><p>'; the_content(); echo'</p></div>

here above is my content div



Here is one way of doing this. You can add additional events depending on requirements.

$(document).on('keyup keypress', '#elementId', function () {
     var maxLength = 100; // maximum number of characters supported
     trimToMaxLength($(this), maxLength);

 function trimToMaxLength(element, maxLength) {
     if (element.val().length > maxLength) {
         element.val(element.val().substring(0, maxLength));

Leave a Reply

Your email address will not be published.

Back to top button