Updated violin .
You can apply the operation to all matched anchors using return:
return $.trim($(this).text()) == "Menu";
If you want to show the div only if there is an anchor with the text Menu , you can use the flag ( menu_exist in my example) in this state, then show if true :
var menu_exist=false; $('.mytext').hide(); $('.label a').filter(function(){ if($.trim($(this).text())=="Menu"){ menu_exist=true; } }); if(menu_exist){ $('.mytext').show(); }
Hope this helps.
var menu_exist=false; $('.mytext').hide(); $('.label a').filter(function(){ if($.trim($(this).text())=="Menu"){ menu_exist=true; } }); if(menu_exist){ $('.mytext').show(); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='label'> <a>Menu</a> <a>Menu Food</a> <a>Menu Drink</a> <a>Cheese</a> </div> <br> <div class="mytext"> this text need hide. </div>
source share