< - start of code - >
var len = 100;
var p = document.getElementById('truncateMe');
if (p) {
var trunc = p.innerHTML;
if (trunc.length> len) {
< - end of sample - >
The codes above are very useful to entertain the viewers of your internet site. Well, what it does is truncate any text enclosed in quotation marks. Sounds simple, don't you think? So why use JavaScript for this feature which seems to be utterly useless to anyone with a mind?
Well, that's because this is a display of simple interactivity provided by your site. Much like
high-tech electronic equipment, the simplest pleasures can send most people praising the mind behind the simple magic of interactivity! With the set of codes above, you have the power to define how much a truncated piece of text would either expand or contract! Yes, all to your pleasure, mind you.
Plus, the set of
JavaScript codes above also provides the user to either expand or contract the pieces of truncated text anytime at will. Yes, by just a click of the mouse! But, always remember, your site should be accessible to the crawlers of the most popularly known search engines, so try to include the full, or complete, text of truncated lines you provide on your site. How? Well, include it on your site's HTML coding, of course!