jQuery recognise click from user, not trigger

javascript, jquery

Solution

`e.which` will be undefined when the event is called by `trigger()`, but will be `1` when you left click on it.

$(".thumbnail_holder .nav li a").on("click", function(e){
    e.preventDefault();

    if (typeof e.which !== "undefined") {
        clearTimeout(window.randomTimer);
    }
});

Other option would be to pass some data when you trigger manually, and check for it in the event handler (see the `extraParameters` argument in `trigger()`.

function randomClick(interval){
    $(".thumbnail_holder .nav li:not(.empty):eq("+select+") a").trigger("click", [true]);
    window.randomTimer = setTimeout("randomClick("+interval+")", interval);
}

$(".thumbnail_holder .nav li a").on("click", function(e, wasTrigger){
    e.preventDefault();

    if (!wasTrigger) {
        clearTimeout(window.randomTimer);
    }
});

Problem

So I have the code: ``` function randomClick(interval){ $(".thumbnail_holder .nav li:not(.empty):eq("+select+") a").trigger("click"); window.randomTimer = setTimeout("randomClick("+interval+")", interval); } ``` I need it so when a user click's `".thumbnail_holder .nav li a`, it clears the interval so for example ``` $(".thumbnail_holder .nav li a").on("click", function(e){ e.preventDefault(); clearTimeout(window.randomTimer); }); ``` However the above code also happens on the `.trigger("click");`. Is there any way the `.on` function can differentiate between the two?

Original source