For Example,
<div style="width:100px;text-align:center">text</div>
I want to get the position and size of the text
text node , not its div
wrapper. Is it possible?
“how to position text in html” Code Answer's 1)static: this is the default value. 2)sticky: the element is positioned based on the user's scroll position. 3)fixed: the element is positioned related to the browser window. 4)relative: the element is positioned relative to its normal position.
The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found.
If the element is in the main document you can get the DIV's coordinates with... var X=window. getComputedStyle(abc,null). getPropertyValue('left'); var Y=window.
In modern browsers (recent-ish Mozilla, WebKit and Opera) you can use the getClientRects()
method of a DOM range that encompasses the text node.
var textNode = document.getElementById("wombat").firstChild;
var range = document.createRange();
range.selectNodeContents(textNode);
var rects = range.getClientRects();
if (rects.length > 0) {
console.log("Text node rect: ", rects[0]);
}
<div id="wombat">Wombat</div>
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