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
2 answers
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