-1

I need a CSS Code or JavaScript Code that can trim a text using it css class.

<h4>
<p class="maocular">12 Chicken Franks Sausage</p>
</h4>

I want to trim any text with css class maocular to 10Characters Pls how can i achieve that with CSS or JavaScript

1 Answers1

0

Using Javascript first get all the elements in the document that have that specific class.

Then iterate through them, picking up their innerHTML and getting just the first 10 characters.

Note: this snippet assumes that the innerHTMLs have only text, with no additional HTML markup in them.

const elements = document.querySelectorAll('.maocular');console.log(elements);
elements.forEach(element => {
  element.innerHTML = element.innerHTML.substring(0,10);
});
<h4>
<p class="maocular">12 Chicken Franks Sausage</p>
</h4>
A Haworth
  • 30,908
  • 4
  • 11
  • 14