Jeff Storey
Jeff Storey

Reputation: 57212

d3 mouse argument with jquery

I am trying to get the mouse coordinates of a div using d3, and I have working code that looks like

var mouse = d3.mouse(document.getElementById('container'));

When I try to use a jquery selector though to do something like

var mouse = d3.mouse($('#container'));

this fails

I also tried

var mouse = d3.mouse(d3.select('#container'));

which also fails.

Is there a more compact way to rewrite my first statement using jquery/d3?

Upvotes: 2

Views: 951

Answers (1)

Selosindis
Selosindis

Reputation: 544

Using the jQuery selector will return a jQuery object. You need to grab the base DOM element using [0]:

var mouse = d3.mouse($('#container')[0]);

I hope this helps!

Upvotes: 2

Related Questions