0

I am filtering a list when a checkox is clicked.I wanna find out if the list is empty, after filtering the list and i want to set a empty text on the list(if there are no li) saying No Data Found. Filter function on check box click:

$('.chk_box').change(function() {
   if ($('input:radio[name=star1]:checked').val()==1) {

     $("#mainpanel").fadeOut(500);
     $("#allapps >li").hide();
     $("#allapps >li[data-rate-filter=1]").show();

   } else if ($('input:radio[name=star1]:checked').val()==2) {
     $("#mainpanel").fadeOut(500);
     $("#allapps >li").hide();
     $("#allapps >li[data-rate-filter=2]").show();
   } 
});

i tried $("#mylistid li").length, but its not giving the length after filtering.

2
  • can you show your html ? Commented Apr 8, 2015 at 11:46
  • <div class="group_container"> <div class="group_header"> <h1>More Recommendations</h1> <div class="clear"></div> </div> <div><ul id="allapps"></ul></div> </div> this is my html... i dynamically append the <li> into the <ul> Commented Apr 9, 2015 at 3:33

1 Answer 1

2

If you hide the filtered items, you can count the not-hidden elements this way:

$("#mylistid li:visible").length

More explanation about the :visible-selector can be found here: https://api.jquery.com/visible-selector/

Sign up to request clarification or add additional context in comments.

2 Comments

hey thanks jordumus it worked.. can u please let me know how can i set a empty text in list (saying no data) when there is no li in the list...thanks again!!!
@prathic Sorry, I didn't get your question, can you give more information? you can just edit your question and add what you want. Just write a comment here afterwards so I get a notification about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.