I want to create a searcher on my website, the problem is that when I show the results of my database, some have a very large description and I'm trying to trunc the description in order to make it more visual.
What I want to do is to show a description that should be like this:
blablabla description bla bla bla more description
into this:
blablabla description bla bla bla mo...
The maximum length that I want to show is 340 characters and the code that I was thinking of is this one
...
var newText = document.createElement("p"); //i create a new element of text
var newContent = document.createTextNode(projects.description); //i set the text to
//be the description from the database [the type of this var is Text]
if(newContent.length > 340) { //if the description is bigger than 340
var result=newContent + ""; //i convert the newContent type to string since
//substring only works with strings and not Text
result=result.substring(0, 337)+"..."; //i trunc the description
newContent=result; // <-- here i need to assign the result[string] to newContent[Text]
}
newText.appendChild(newContent);
...
Hope you can tell me how to convert the string to Text again or another way to trunc the description.
Thanks, Bertran