$(document).ready(function() { var counts = $('#grid li a').size(); $('.col-lg-9 p').text('at the moment their ' + counts); }); $('.col-lg-3 p').click(function(e) { e.preventDefault(); var a = $(this).attr('data-id'); a = a.substr(1); $('#grid li a').each(function() { if (!$(this).hasClass(a) && a != 'all') $(this).addClass('hide'); else $(this).removeClass('hide'); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="row mt"> <div class="col-lg-9"> <h1>Hello, my works below</h1> <p></p> </div> <div class="col-lg-3"> <p data-id="#optam" class="pull-right"><br><button type="button" class="btn btn-blue">optam</button></p> <p data-id="#math" class="pull-right"><br><button type="button" class="btn btn-blue">math</button></p> <p data-id="#all" class="pull-right"><br><button type="button" class="btn btn-blue">all</button></p> </div> </div> </div> <div id="portfolio"> <div class="container"> <div class="row mt"> <ul class="grid effect-2" id="grid"> <li> <a class="optam" href="proj/p5.html"><img src="assets/img/portfolio/cpp5.jpg"></a> <h2>Practical 5</h2> </li> <li> <a class="math" href="proj/p5.html"><img src="assets/img/portfolio/cpp5.jpg"></a> <h2>Practical 5</h2> </li> </ul> </div> </div> </div> When I click the math or optam button in the col-lg-3 class , the piccha that does not fit the filter disappears, but <h2>Practical 5</h2> remains. Tell me what's the problem?