Skip to content

Instantly share code, notes, and snippets.

View huo-feng-ding's full-sized avatar
🌈
On vacation

火风鼎 huo-feng-ding

🌈
On vacation
View GitHub Profile
@huo-feng-ding
huo-feng-ding / README.md
Created March 28, 2019 11:39 — forked from biovisualize/README.md
d3.selection.appendHTML and appendSVG

Parse and append an HTML or SVG string. I use it a lot for appending a template, instead of generating it with d3.

d3.select('.container').appendHTML('<div><svg><g><rect width="50" height="50" /></g></svg></div>');

Unlike using .html, .appendHTML can append multiple elements

d3.select('.container').html('<span id="a"></span>');
d3.select('.container').html('<span id="b"></span>'); // will replace content
d3.select('.container').appendHTML('<span id="c"></span>'); // will append content