3

I try to trigger an event on user click, then I used the on click method of JQuery. The problem is that I create my element after my onclick function. I've read here or here that we can add a balise name between click and the function but my code return n.apply is not a function

Here is my JQuery method:

d3.selectAll("body")
     .on('click', '.child', function(){
                console.log("here");}

and later on,this code return the good elements :

console.log(d3.selectAll("body .child"));
Community
  • 1
  • 1
Pierre GUILLAUME
  • 450
  • 3
  • 24

3 Answers3

1

Try this : use $(document) as parent element to delegate click event calls

$(document).on('click', '.child', function(){
     console.log("here");
});
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
1

You can add a handler while you creating an element. Just create a jQuery OBject and append this to whatever you need. Note: The Click function can also be inline.

Example: https://jsfiddle.net/rfccvgLm/
CT24
  • 36
  • 3
0

it seems - as far as the syntax is ok - that the handlers are not registered, because d3.selectAll does not return no elements to register the event on

or hor
  • 723
  • 3
  • 11