2

I want to add "mousedown" event to the plot holder in JQuery/Flot code, i tried two ways, but neither works, i appreciate anybody give me any hints!

1)

placeholder.bind("mousedown",function(e){
    alert("1");
})

2)

function onMouseDown(e) {
    alert("1");
}

plot.hooks.bindEvents.push(function (plot, eventHolder) {
    eventHolder.mousedown(onMouseDown);
});
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Simon
  • 1,463
  • 6
  • 34
  • 46
  • What is placeholder? How is it defined? [example here](http://jsfiddle.net/Qnff3/) – Scoobler Apr 18 '11 at 15:44
  • Hi Scoobler, good example for me as a newbie. i just added more detials to this question. hope you have some time to take a look, thanks a lot! http://stackoverflow.com/questions/5737347/extjs-jquery-flot-mousedown-event-for-the-plot-container – Simon Apr 20 '11 at 22:27

3 Answers3

0

In flot , You can bind events using hooks . There is a hook called bindEvents which you can use to bind any event.

example:

     function myClick(plot, eventHolder){
       eventHolder.mouseover((e)=>console.log('You preses the mouse at',e.pageX+""+e.pageY))
     }

     let options = { hooks: {bindEvents: [myClick]}}

The Documentation is in good detail about this https://github.com/flot/flot/blob/master/API.md

sridhar..
  • 1,945
  • 15
  • 19
0

Simon ,

If they are dynamically added elements after the DOM , try live . Normal bind doesn't work if they are added at run time.

http://api.jquery.com/live/

kobe
  • 15,671
  • 15
  • 64
  • 91
  • hi. thanks for this advice. however, it still doesnt work. placeholder.live("mousedown",function(e){ alert("1"); }) – Simon Apr 18 '11 at 03:41
0

I would guess that you've mistaken what the call to $.plot returns. It doesn't give you back a jQuery object, it gives you back a Plot object.

So most likely, if you have something like this as your HTML:

<div id="placeholder" style="width:600px;height:400px"></div>

You want to do a bind like this:

$('#placeholder').mousedown(function(){
  alert('mouse down')
});
Ryley
  • 21,046
  • 2
  • 67
  • 81
  • hi Ryley,thanks for your reply. i just added some details to this question, appreciate any comments while you have time to take a look. thanks. http://stackoverflow.com/questions/5737347/extjs-jquery-flot-mousedown-event-for-the-plot-container – Simon Apr 20 '11 at 22:25