I have some set of div which has a class name. Here I want to control/limit the number of characters to be displayed in the div based on the class name using JavaScript. How can I fix this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is the jQuery solution for limiting the elements with
.myclassto 200 chars:The pure JavaScript solution (for all browsers that don’t support
getElementByClassname) would look like this:Note that the pure JavaScript method may create invalid HTML if the divs contain markup. The correct way would be to iterate over the child nodes in the div.