How to find all the Nodes from the Selection

By Akbar

Today when working on a JavaScript function to get all the DOM nodes which are under selection, I was going through the compatibility tables at and scratching my head and wondering why the W3C guys have made this basic job all that difficult. I must admit that playing with range is complex (specially how it can span over the multiple nodes and partially covered), but it’s definitely not as complex as mad by some of the available methods. Plus that there are many comparability differences between browsers :-)

Tired of looking at the compatibility tables, I thought to give it another search try at Google and Voilla! I found the exact code I was looking for at

The purpose of this post is that give a big thanks and credit to Elgi for sharing this code, and for keeping this useful info handy.

Tags: , ,