Peter Saxton
Peter Saxton

Reputation: 4676

binding predefined functions to Jquery events

I have a working script to apply transformations to SVG so that the image is draggable. The script works when I use the attributes of the html element.

<g id="all" onmousedown="startMove(evt)" onmousemove="moveIt(evt)" onmouseup="endMove(evt)">

However I would like to bind the events with Jquery something like below and wonder where I am going wrong with the code below

$('svg > g').mousedown(startMove(evt));
$('svg > g').mousemove(moveIt(evt));
$('svg > g').mouseup(endMove(evt));

Upvotes: 0

Views: 710

Answers (2)

Johan
Johan

Reputation: 35194

Try this:

$('svg > g').mousedown(function(evt){
    //do stuff
});

or even

$('svg > g').mousedown(startMove);

function startMove(evt){
    //do stuff
}

startMove references the actual function, while startMove() uses it's return value.

Upvotes: 1

Dale
Dale

Reputation: 10469

I believe you have to do it like so:

$('svg > g').mousedown(function(evt){
    startMove(evt);
});

Upvotes: 0

Related Questions