-
-
Save dylansm/857add123c57e3911b748fa3ee0f23d8 to your computer and use it in GitHub Desktop.
size of TextNode - DOM Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the coolest code snippet I (Mr. Mad) have every created | |
// It will magicly get the size of a textnode, by createing a context | |
// range and get the client rects of that range. | |
// It will then combine the rects to one rect, and thereby get the size | |
// of the text node. | |
// Note that by any standarts a TextNode has no size. | |
var range = document.createRange(); | |
range.selectNode(node); | |
var rect = range.getBoundingClientRect(); | |
// The magic ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment