Here you go MS Boy... :-)
<html>
<head>
<script>
function boundDim(oObject)
{
var oTextRange = document.selection.createRange();
if (oTextRange != null) {
alert("The bounding left is \n" + oTextRange.boundingLeft);
oTextRange.pasteHTML("<b>" + oTextRange.htmlText + "</b>");
}
}
</script>
</head>
<body onclick="boundDim(this);">Hello to all. Hello to me.</body>
</html>
The above is just a small example on what you can do with the API. Once the text is selected, you get its offset in pixels which you can then use to distinguish between the first and second foobar.
If my snippet doesn't give you what you need, also read on
selection and
range.
Do let me know if it works.
I don't accept change; I don't deserve to live.