Last Updated: February 25, 2016
·
2.256K
· david morrow

Scoping D3 to your Backbone view

Recently I used D3 in combination with Backbone.js. Normally when inside a backbone view, you only access the dom elements inside the template you have rendered

var $bar = this.$el.find('.bar')

When selecting objects with D3 instead of jQuery or whatever, I needed to scope my selector to within the Backbone view's scope

var bar = d3.select(this.el).select('.bar')

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside