i have a problem. i load some text from the db. On my page, i only want to show 30 first words of this text. I will then add a ‘read more’ button, which will redirect the user to a new page. So the ‘jquery expander plugin’, which will show the remaining text in the same div, will not work for me I think.
i got this far:
$content = $("#blog_1").find(".entryContent").text().split(" ");
$slicedContent = $content.slice(30);
I have been messing around with .split and .slice for hours. But no success.
I don’t even have to ‘keep’ the remainder of the text, since it will be loaded again when the user will click read more, on the ‘detail page’. So onwards from word 30, the text could be removed from the DOM.
answers regarding displaying a set number of characters instead of words are also helpful.
Thanks in advace!
To answer your question first, it’s like this:
I would not do this though. It’s better to limit on the amount of text instead, then there is less worry about having to detect word beginnings/endings. It will also make styling easier and more predictable.
Better yet again is to limit the generation of this text server side. It’s just a plain wasted of bandwidth to send all that data down and not use it.