Kevin
Kevin

Reputation: 653

How to use jquery trigger function?

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>

Upvotes: 0

Views: 38

Answers (1)

Nutshell
Nutshell

Reputation: 8537

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/

Upvotes: 2

Related Questions