in Education by
I am paginating users and in my view I have: <%= user.profile %> I want to limit li.profile to 200 characters followed by three dots '...' Below does not work: $(document).ready(function(){ $("li.profile").each(function(){ if ($(this).html().length > 200) { $(this).html($(this).html().substr(0, 200)); $(this).append('...'); } }); }); this is the way it looks in developer tools. css li.profile { font-size: 14px; padding-bottom: 5px; text-align: left; padding-left: 5px; } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Use .text(); .html() sets .innerHTML of element, not .textContent $(document).ready(function(){ $("li.profile").each(function(){ if (this.textContent.length > 200) { $(this).text(function(_, text) { return text.substr(0, 200).concat("..."); }) } }); });

Related questions

0 votes
    I am trying to set text and value for both td tag and input tag at the same time. But after ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I am trying to set text and value for both td tag and input tag at the same time. But after ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    We are planning to use the jQuery library to augment our client side JavaScript needs. Are there any major ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I am new to jquery and now trying to create a fancy box in jquery . I will explain its ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am new to jquery and now trying to create a fancy box in jquery . I will explain its ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am new to jquery and now trying to create a fancy box in jquery . I will explain its ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do: when an element with any class listed in an array is clicked, the class ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do: when an element with any class listed in an array is clicked, the class ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do: when an element with any class listed in an array is clicked, the class ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    What I'm trying to do: when an element with any class listed in an array is clicked, the class ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    When I use ajax call from a modal window, the request url seems not correct. I have a webserver ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: jQuery in Greasemonkey 1.0 conflicts with websites using jQuery (3 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I'm trying to capture the event of opening and closing the bootstrap accordion, but with the typescript the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    i have a control that is organized like this and i want to have the javascript registered on the calling ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    i have a control that is organized like this and i want to have the javascript registered on the calling ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
...