0

I'm trying to limit the characters in a block, and I've managed to do it like this (I've followed this solution)

      $(".nome-produto").text($(this).text().substr(0, 70)+'...');

It's working as needed, but the problem is I have multiple items, and the text is being copied...

The printscreen is here

Any clues?

0

2 Answers 2

2

You need a function that will return correct text for every node in the matching set.

$(function(){
   $('.nome-produto').text(function(_, text){
       return text.substr(0, 70) + '...';
   });
});
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you are using a class selector so I believe the jquery statement you are using would be applied to all items of that class. You could either have a statement for each item (not desirable) or you should be able to do something like:

$(".nome-produto").each( function() {
   $(this).text($(this).text().substr(0, 70)+'...');
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.