0

I have two functions one sidefilter and another is topfilter.

user.js

sidefilter();
function sidefilter(){
    $('.sidefilter').unbind("click");
    $('.sidefilter').on("click",function(e){
        var fid=$(this).attr('data-id');
        var filtertype=$(this).attr('data-type');
        var type = $('.view-list').hasClass("active")?"list":"grid";
        $.post(urljs+"user/FilterController/index",{'fid':fid, 'filtertype':filtertype, 'type':type},function(data){
            $("#sidefilter").html(data.view);
            sidefilter();
            topfilter();
        },"json");
        e.preventDefault();
    });
}

topfilter();
function topfilter(){
    $("[name=topfilter]").unbind('change'); 
    $("[name=topfilter]").on("change",function(e){


   **I want to use trigger event here and use of that i want call sidefilter function. This topfilter is drop down input**

        },"json");   
    });
}

courses.php

 <select class="select" data-type="topfilter" name="topfilter" id="all-categories">
    <option value="">All</option>
    <option value="1">Beginer</option>
    <option value="2">Intermediate</option>
    <option value="3">Professional</option>
 </select>

1 Answer 1

2

Here's an example of how to use trigger() function : See this fiddle

JS

$('.sidefilter').click(function(){
    alert('triggered!');
});

$("[name=topfilter]").on("change",function(e){
  $('.sidefilter').trigger('click');
});

Hope it helps !

Docs : http://api.jquery.com/trigger/

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

4 Comments

yes its working but that sidefilter function 6 times there in my js but I need it trigger only once. How to do?
I don't understand what is triggered 6 times, but maybe change the name of class elements to make the code works on a specific class or use an ID ?
6 sidefilter function are in my js. All are trigering
Ok so use an ID to the specific one you want to trigger and change the selector when you call the trigger : example : $('#sidefilter').trigger('click');

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.