10

JQuery.filter () Question

Given the following HTML:

<div class="parent">
<span class="child">10</span>
</div>

<div class="parent">
<span class="child">20</span>
</div>

I want to filter and hide the parent div based on this span value (child value), so I thought about doing something like:

<script>
$('span.child').filter(function(index) {
 return ($(this).text() < '15');
}).$(this).parent().hide();
</script>

No success ... I do not hide the parent div based on the value of Span.

Can anybody help me?

Really appreciate.

+3
source share
2 answers

Try the following:

jQuery('span.child').filter(function(index) {
   return (jQuery(this).text() < '15');  
}).parent().hide();
+2
source

Just delete the last one $(this), for example:

$('span.child').filter(function(index) {
  return $(this).text() < '15';
}).parent().hide();

.filter()returns a filtered set of elements, it takes what you have selected, filters out what you need, and then just cling to the result. You can see how it works here .

+2
source

Source: https://habr.com/ru/post/1740336/


All Articles