[jQuery] each() causing me jip :[

[jQuery] each() causing me jip :[


Hey guys,
If you can help me with the fix (line: 9) below that would be great.
each() is causing the problem for me, as it's performing the code on
each

and not the total

's. Can anyone suggest a solution?
// create a 'continue reading' - linked to the single post page -
if .scrollableItem's paragraph content exceeeds set quota
$(document).ready(function () {
// set word limit
var quota = 20;
    $('.scrollable .scrollableItem p').not('.wp-caption-text').not
('.postmetadata').each(function () {
        // count the no. of words in the post and assign to var totalWords
(fix: presently this counts no. of words in EACH paragraph. we need
no. of words in ALL paragraphs here.)
        var string = $(this).text();
var count = string.split(" ");
var totalWords = count.length;
// set up post variables
var postTitle = $(this).parent().find('h2').text();
var postURL = $(this).parent().find('h2 a').attr('href');
// if word limit is reached drop in a 'continue reading' link
if (totalWords >= quota) {
            $(this).parent().find('.postmetadata').before('<p
class="readMore"><a href=' + '"' + postURL + '"' + '>Continue
reading:' + postTitle + '</a>




















');
};
});
});
Thanks,
L









    • Topic Participants

    • mail