I have the following div
s in an HTML page:
<div class="foo">Bar</div>
<div class="foo">Baz</div>
I'd like to get an array with the text contained in the two div
s:
['Bar', 'Baz']
I can do this using d3.nodes
but it seems a bit clunky. Is there a smarter way?
d3.selectAll(".foo").nodes().map(function(d) { return d.innerHTML; });
The answer could be pure Javascript, of course!
var text = [];
document.querySelectorAll(".foo").forEach(function(e){
text.push(e.textContent);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With