javascript - trying to find if title contains word then hide that parent element -
var search_input = $('#input_search'); var search_console = search_input.val(); var header_console = $('.header'); $('#enter_console').click(function() { var bodies = $('.reviews'); for(var i=0;i<bodies.length;i++){ var bodies = bodies[i]; if($(bodies).find(header_console).filter(':contains("+search_console+")')) { bodies[i].hide(); } } });
i trying find if bodies has word user types in in input. if bodies has word hide rest of elements except it. can me??? basic html looks like
<div id="2343" class="reviews"> <h2>animal crossing: city folk</h2><h3 class="header">wii</h3> <p>8/10</p> <img src="http://i1231.photobucket.com/albums/ee512/rukiafan23/1_zpsdab192dc.jpg" alt="{title}"> <a href="http://www.wiiwarewave.com/t93-animal-crossing-city-folk"> read review </a> <div class="inner_box_review">----</div> </div>
this should it:
$('#enter_console').click(function() { var search_input = $('#input_search'), search_console = search_input.val(), header_console = $('.header'); $('.reviews:has(.header:contains("' + search_console + '"))').hide(); });
fixed quote issue well.
the selector says: "select elements class "reviews" have @ least 1 descendant contains text stored within search_console
."
if need opposite , hide dont have said text, need .not(
or :not()
$('#enter_console').click(function() { var search_input = $('#input_search'), search_console = search_input.val(), header_console = $('.header'); $('.reviews').not(':has(.header:contains("' + search_console + '"))').hide(); });
or
$('#enter_console').click(function() { var search_input = $('#input_search'), search_console = search_input.val(), header_console = $('.header'); $('.reviews:not(:has(.header:contains("' + search_console + '")))').hide(); });
Comments
Post a Comment