开发者

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 parent div based on it's span value (child value), so have thought of doing something like:

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

No success... I am not hiding Parent div based on Span Value..

Anyone can help me ?

Greatly apprec开发者_如何学Goiated.


Try this:

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


Just remove that last $(this), like this:

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

.filter() returns the filtered set of elements, it takes what you selected, filters out what you wanted gone, then you just keep chaining the result. You can see this working here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜