About

Labels

slider

Navigation

How to make the text shorter for home page in blog post?

Making of text shorter or to minimize sometimes becomes necessary to get a better design.I'm going to share how to make it shorter using Jquery and Javascript,but you must know the basic of Jquery to work with it so lets start with it.
For instance your post is having structure something like this one
<div class='post'>
  Ea eam labores imperdiet, apeirian democritum ei nam, doming neglegentur ad vis. Ne malorum ceteros feugait quo, ius ea liber offendit placerat, est habemus aliquyam legendos id. Eam no corpora maluisset definitiones, eam mucius malorum id. Quo ea idque commodo utroque, per ex eros etiam accumsan.
Eu mei solum oporteat eleifend, libris nominavi maiestatis duo at, quod dissentiet vel te. Legere prompta impedit id eum. Te soleat vocibus luptatum sed, augue dicta populo est ad, et consul diceret officiis duo. Et duo primis nostrum.
</div>
So to make it short a we use .substr function which extract a particular part of a text.So we do something like this one.
$('.post').each(function(){
  var text=$(this).text();
  var count=100;
  if(text.length>count){
    var cut=text.substr(0,count);
  }
  else{
    var cut=text;
  }
  $(this).html(cut+"...");
});
Now the result will be 
Want to ask something? We are waiting for comments.

Image Credit:smashingmagazine.com
Share
Banner

Muhammad Hamza

Themelet provides the best in market today. We work hard to make the clean, modern and SEO friendly blogger templates.

Post A Comment:

0 comments: