DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Hide Portion Of Text

  • submit to reddit
        // Just here for my reference really

$(".discussion-item:not(.child) a p").each(function() {
    var iLimit = 155;
    var sExcerpt = $(this).html().substr(0, iLimit); // Get the visible part of the string
    var sHiddenText = $(this).html().substr(iLimit, $(this).text().length); // Get the hidden part of the string
    // Set the new text with 
    $(this).html(sExcerpt + "<span class=\"hidden\">" + sHiddenText + "</span>");