25

Does anyone know the d3 equivalent to jQuery attribute selector:

$('[attribute="name"]')

I want to be able to use d3 methods such as .transition(). Thanks!

mike
  • 22,931
  • 31
  • 77
  • 100

1 Answers1

30

It's the same in both D3 and jQuery; the underlying functionality is provided by the W3C Selectors API, so see the documentation on attribute selectors. For example, d3.select("[id=body]") is equivalent to d3.select("#body").

mbostock
  • 51,423
  • 13
  • 175
  • 129
  • mike .. are you sure there's not some difference in implementation? `$("svg.overview").find(".node[data-index=0]")` returns the element, `d3.select("svg.overview").selectAll(".node")` returns the element and 6 others - while `d3.select("svg.overview").selectAll(".node[data-index=0]")` throws "Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Element': '.node[data-index=0]' is not a valid selector. at SVGSVGElement." – pstanton Apr 08 '19 at 04:46
  • ah ! it's ok if i quote the value ie `.node[data-index='0']` – pstanton Apr 08 '19 at 04:49