Don't use raw text values as the node ids or class names. You end up with all sorts of escaping issues, which you've already encountered judging by all the select("[id=... shenanigans. It also opens you up to XSS attacks and makes the document unnecessarily large. Instead, construct a simple map from text values to generated IDs or class names. The D3 ordinal scales can help you out with this.
Don't use raw text values as the node ids or class names. You end up with all sorts of escaping issues, which you've already encountered judging by all the
select("[id=...
shenanigans. It also opens you up to XSS attacks and makes the document unnecessarily large. Instead, construct a simple map from text values to generated IDs or class names. The D3 ordinal scales can help you out with this.