0

How can I change the "20" into the variable "words"?

var words = 125;

$(".px-text-module-<?php echo $id; ?>").html($(".px-text-module").html().replace(/([a-zA-Z]+[.,]? ){20}/, function(x) {
  return '<div class="read-more-wrapper"><p class="read-more-content">' + x + '<span class="read-more-dots">...<br></span></p></div><p>';
}));
}

This should be the code but it does not work:

var words = 125;

$(".px-text-module-<?php echo $id; ?>").html($(".px-text-module").html().replace(/([a-zA-Z]+[.,]? ){words}/, function(x) {
      return '<div class="read-more-wrapper"><p class="read-more-content">' + x + '<span class="read-more-dots">...<br></span></p></div><p>';
    }));
    }
Bob
  • 415
  • 6
  • 15
  • this is bad 'px-text-module-' because you have not php on output but number, so this selector does not work – daremachine Aug 24 '22 at 10:18
  • It does work, but I edited the code. It's about the the replace function where it says {words} I cannot pas a variable into it. – Bob Aug 25 '22 at 14:13

0 Answers0