B
B
Berzeg2018-02-20 20:37:24
JavaScript
Berzeg, 2018-02-20 20:37:24

How to remove elements of a list that do not meet a condition?

There is a list like this

<ul class="list-box">
  <li><a class="link">Белая ткань (0)</a></li>
  <li><a class="link">Черная ткань (1)</a></li>
        <li><a class="link">Синяя ткань (0)</a></li>
        <li><a class="link">Серая ткань (20)</a></li>
  <li><a class="link">Бирюзовая ткань (10)</a></li>
</ul>


Question - how to remove all elements with the number zero, in this form, without enclosing the numbers in a separate tag?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2018-02-20
@Berzeg

$(".list-box li a").each(function() {
  if($(this).text().indexOf('(0)') != -1){
    $(this).parent('li').remove();
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question