javascript - Hide content not containing select box value -
i have page filter shown content country, using select box. page shows content, when country selected, doesn't match value hidden adding css class.
this relevant code far:
jsfiddle
html:
<select name="filter" id="filter"> <option value="" disabled selected></option> <option value="france">france</option> <option value="germany">germany</option> <option value="uk">uk</option> </select> <div class="media"> <p>blah blah blah france blah blah</p> </div> <div class="media"> <p>blah blah blah germany blah blah</p> </div> <div class="media"> <p>blah blah blah germany blah blah</p> </div> <div class="media"> <p>blah blah blah uk blah blah</p> </div>
css:
.hidden { display: none; visibility: hidden; }
javascript:
$('#filter').change(function () { var country = $('#filter').val(); $('.media').each(function () { if ($('.media').find(country)) { } else { $('.media').addclass('hidden'); } }) });
i have little experience jquery/javascript, i've investigated , think need loop through matching content "blocks" each()
, each time looking relevant content find()
, don't know enough working. code nothing whatsoever.
any appreciated.
do want this:
$('#filter').change(function () { var country = $('#filter').val(); $('.media').hide(); $('.media:contains('+ country.tolowercase() +')').show(); });
demo
or:
$('#filter').change(function () { var country = $('#filter').val(); $('.media').addclass('hidden'); $('.media:contains(' + country.tolowercase() + ')').removeclass('hidden'); });
Comments
Post a Comment