Can I get the offset of a selected html element in the html source code?
for example:
<html>
<body>
<a href="http://google.com">google</a>
</body>
<html>
if the user would select the google text, I would want to get 40 as this is the offset from the start of the source.
I tried with Range object but couldn't find something helpful with this one.
Thanks!
<html>
<head>
<script>
function srcOffset(ele)
{
alert(document.getElementsByTagName('html')[0].innerHTML.indexOf(ele.id) + ele.id.length + 2);
return false;
}
</script>
</head>
<body>
<a href="http://www.google.com/" onclick="return srcOffset(this)" id="myLink">Google</a>
</body>
</html>
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