0

I am using quicksand jquery and i have searched for solutions and none work. I am trying to auto-click a category when the page loads to filter what I want to filter.

Here is the links on the page that allow users to click and filter

<li><a href="javascript:void(0);" id="all">Everything</a></li>
<li><a href="javascript:void(0);" id="cat1">cat1</a></li>
<li><a href="javascript:void(0);" id="cat2">cat2</a></li>
<li><a href="javascript:void(0);" id="cat3">cat3</a></li>
<li><a href="javascript:void(0);" id="cat4">cat4</a></li>

when the page loads, it show ALL items and then the user can select the category to filter by. i want to auto click one, and am looking for the function to generate the click.

here is what i have tried with no solution:

   <script type="text/javascript">
   $(document).ready(function() {
   $(".filter li a.cat2").trigger('click');
  });
 </script>

and
      <script type="text/javascript">
       $(document).ready(function() {
      $(".filter li a.cat2").trigger('click');
     });
    </script>

and

<script>
$(function() {
// It would be better to create a function for this, but
// to avoid code duplication the click() event is triggered/reused
$('.filteroptions li a cat2').click();
});
 </script>

Here is the js file it operates from and why i chose to remove "filteroptions" and try "filter" as was suggested in other posts. as mine shows ".filter li a" not filteroptions li a

// DOMContentLoaded
 $(function () {
// bind radiobuttons in the form
var $filterType = $('.filter li a');

// get the first collection
var $applications = $('#list');

// clone applications to get a second collection
var $data = $applications.clone();



// attempt to call Quicksand on every form change
$filterType.click(function (e) {

    $('.filter li a').removeClass('selected');
    $(this).addClass('selected');
    if ($(this).attr('id') == 'all') {
        var $filteredData = $data.find('li');
    } else {
        var $filteredData = $data.find('li[class=' + $(this).attr('id') + ']');
    }
    // finally, call quicksand
    $applications.quicksand($filteredData, {
        duration: 800,
        easing: 'easeInOutQuad',
        attribute: 'id'
    }, function () {
        $("a[data-rel^='prettyPhoto']").prettyPhoto({ animationSpeed: 'slow', social_tools: false, slideshow: 2000 });
    });
});

});

And here are other posts that you may say are the same, but i tried them and they do not work. They are using an older type of quicksand.

JQuery Quicksand: Link directly to pre-filtered Quicksand from another page

First open limited item not all in jQuery Quicksand?

Community
  • 1
  • 1
ant t
  • 25
  • 8

1 Answers1

2

You are using id on not class so change your click tigger to

$(".filter li #cat2").trigger('click');
Diptox
  • 1,809
  • 10
  • 19