Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a mouse move event from jQuery

I'm trying to manually trigger a mousemove event with jQuery. Demo in this fiddle http://jsfiddle.net/qJJQW/

From other similar posts on Stack Overflow it seems that this should work. Why isn't it?

like image 383
hofnarwillie Avatar asked Oct 22 '13 10:10

hofnarwillie


2 Answers

Use jQuery to bind the mousemove event:

$(function () {
   $("#test").on("mousemove", youCantHandleTheFunc);

    $('#button').click(function () {
        $('#test').trigger('mousemove', {type:'custom mouse move'});
    });
});

function youCantHandleTheFunc (e,customE) {
    if (customE != undefined) {
         e = customE;   
    }
    $('#result').html(e.type);
}

Your updated fiddle.

like image 107
karim79 Avatar answered Sep 18 '22 02:09

karim79


jQuery's trigger() only triggers event handlers set with jQuery ?

$(function(){
    $('#test').on('mousemove', youCantHandleTheFunc); 

    $('#button').click(function(){
        $('#test').trigger('mousemove',{type:'custom mouse move'});
    });
});

function youCantHandleTheFunc(e,customE){
    if (customE!=undefined){
         e=customE;   
    }
    $('#result').html(e.type);
}

FIDDLE

like image 39
adeneo Avatar answered Sep 18 '22 02:09

adeneo