I have this code (assume unable to modify)
<div class="parent">
<div class="wrap">
<span class="content">2026-01-31-08:00</span>
</div>
<div class="wrap">
<span class="content">2025-03-34-06:00</span>
</div>
<div class="wrap">
<span class="content">N/A</span>
</div>
<div class="wrap">
<span class="content">N/A</span>
</div>
</div>
The "2026-01-31-08:00" are supposed to be dates, "N/A" should stay the same. I’m trying to format the dates by cutting off the extras with .slice
, and format it to say "01/2026" and "03/2025" while the "N/A" stay the same.
I tried to use :contains
to select the ones with number then format it but with no luck. Any ideas how to do so?
2
Answers
You’ll want to filter the elements by matching their content to a regular expression. Then replace the contents of those elements with the new text
It’s 2022 and you might not need jQuery
You can use :contains(‘-‘) to search for the hyphen.