Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to compare a string with number

I have a span id with textContent which have their own time(hour/minutes)

<div class="here">
<span class="time" >8 min</span>
</div>
<div class="here">
<span class="time" >22 min</span>
</div>
<div class="here">
<span class="time" >38 min</span>
</div>
<div class="here">
<span class="time" >1 hour</span>
</div>
<div class="here">
<span class="time" >1 day</span>
</div>

How can we show the span text whose time is less then 60 min, i don’t want to show the text of span which contains 1 hour or 1 day any way to do that and yes string with number is necessary for my project.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

const els = document.querySelectorAll(".time")
els.forEach(el => {
  if (/(hour)|(day)/.test(el.textContent)) el.style.display = "none"
})
<div class="here">
  <span class="time">8 min</span>
</div>
<div class="here">
  <span class="time">22 min</span>
</div>
<div class="here">
  <span class="time">38 min</span>
</div>
<div class="here">
  <span class="time">1 hour</span>
</div>
<div class="here">
  <span class="time">1 day</span>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading