How to trigger a mouse move event from jQuery

I am trying to manually fire an event mousemoveusing jQuery. Demo in this fiddle http://jsfiddle.net/qJJQW/

From other similar posts in stackoverflow, it seems like this should work. Why is this not so?

Thanks to everyone.

+4
source share
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 script.

+3
source

Does jQuery trigger()only fire event handlers defined using 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

+4
source

All Articles