I want to set a Max length of 60 characters in titles, using pure JavaScript. But it does not want to work.
Here is the html
<div class="limiter">
Pandemic deaths are spiraling
out of control since the
opening of the country
and now we test the limiter
</div>
Here is the JavaScript
document.querySelector(".limiter").each(function () {
var a = 60;
var b = document.querySelector(this).text();
if (b.length > a) {
document.querySelector(this).text(b.substring(0, a + 1) + " ...");
} else {
document.querySelector(this).text(b);
}
});
Any idea why it does not work ?