Telefisch
Telefisch

Reputation: 315

HowTo select an Element by its ID (d3)


I have some Problems with d3-selection. I did it hundrets of times in my Project but now I have a hole in my head.

var draggedLine = d3.select('line');

works as expected (Returns the first line)

var draggedLine = d3.select('#76');

throws a Syntax Error in d3.v4.js.

d3.v4.min.js:2 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#76' is not a valid selector.

What is wrong here?
(of Course the Element with id="76" exists. It's a Group Element)

Upvotes: 1

Views: 719

Answers (1)

gowtham rajan
gowtham rajan

Reputation: 322

Solution Try this

var draggedLine = d3.select('[id="76"]');

Note: id should not start with number for better approach

Upvotes: 1

Related Questions