Himmators
Himmators

Reputation: 15006

Add buttons to svg-object with javascript

I'm building a graph in javascript using nvd3 and need to add a couple of custom buttons.

using d3 I only seem to have an append-object. In my current setup, self.selector is a svg-element.

d3.select(self.selector).insert("button")

I consider a few options:

Are there any pro:s or cons with any of theese methods? I don't use jQuery in this project.

Upvotes: 1

Views: 1549

Answers (2)

Marcel Böttcher
Marcel Böttcher

Reputation: 185

I would recommend adding SVG shapes, style them with CSS to look like the buttons you want and register and event listener. That works fine and is the cleanest approach.

Upvotes: 3

Elijah
Elijah

Reputation: 4639

You cannot add HTML button elements to SVG, the SVG containers (svg and g) cannot hold buttons. You can add foreignObject to an SVG canvas (or g element) which can hold buttons but svg:foreignObject is not supported in IE.

Upvotes: 0

Related Questions