Take the 2-minute tour ×

I would like to add an eventhandler with dart to a div that fires an js event so I do this over jquery,
when the event is fired from the div, the callbackmethod is called as expected, but the divs that are parents of the div, which fires the event, are removed.

They are completely removed from the dom.

js.scoped(() {
   js.context.$(new js.Callback.once(($) {
      $('#mySlider').on('change', new js.Callback.many(() {
           print('Element changed');

Do anybody knows why dart or jquery does this? Or which of both is responsible for it?

share|improve this question
add comment

1 Answer

In dartium the following code should work :

js.context.$('#mySlider').on('change', new js.Callback.many((_) {
  print('Element changed');

With dart2js (which also use $) you have two options :

  • compile with --global-js-name option to change $ to something else.
  • call $.noConflit() before the dart script is loaded to release $ used by jQuery and change js.context.$ with js.context.jQuery in the above code snippet.

Some comments on your code :

  • it's not necessary anymore to use js.scoped
  • the callback is called with one parameter so you have to define it even if you don't use it (that why I use a _ to handle this parameter that I don't care)
share|improve this answer
Ok, your comments are really helpful. the js.scoped is really inconvenient and the problem with the $ come up 5min ago, while testing the application in firefox. But sadly it does not solve my problem with the missing div blocks. –  user2520673 Jun 25 '13 at 18:43
I had tested my code snippet and it was working great. I don't see any reason for this code to remove a div. This behaviour should come from an other place. –  Alexandre Ardhuin Jun 25 '13 at 18:58
add comment

Your Answer


