I’m looking to select a range with javascript createRange function. I’m just now after so many years discovering this function, and it’s one of those DOH! moments.
Is there a way to select all the elements in a given parent. Currently, I have a div full of content I’m trying to select. This content may be text nodes, elements, IDK.
var container = document.getElementById('mydiv');
var range = document.createRange();
range.setStart(container, 0);
range.setEnd(container, ???);
Is there an accurate, easy, efficient way to get the length of content in the parent (container)? Or is there a hidden method with range that does this already?
No libraries, please! Not terribly concerned with cross-browser fall-backs, but insights into them are welcome if you have any.
EDIT
For clarity, I’m NOT looking to get the innerHTML, but rather a range object. So PLEASE don’t say “why not just use innerHTML”.
selectNodeContentsdoes the trick, getting the content of the specified element.