Is it possible to determine the caret position, in terms of x/y
pixels, within a textarea? (I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)
-Derik
(OTOH, finding the Caret position-- between what characters the cursor
is positioned-- uses the function below. I include it to be nice to
future searchers, and because it took me an hour of frustrated
searching to find.)
function getCaretPos(el) {
if (typeof el.selectionSta rt != 'undefined')
return el.selectionSta rt;
else if (document.selec tion)
return
Math.abs(docume nt.selection.cr eateRange().mov eStart('charact er',
-1000000));
}
pixels, within a textarea? (I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)
-Derik
(OTOH, finding the Caret position-- between what characters the cursor
is positioned-- uses the function below. I include it to be nice to
future searchers, and because it took me an hour of frustrated
searching to find.)
function getCaretPos(el) {
if (typeof el.selectionSta rt != 'undefined')
return el.selectionSta rt;
else if (document.selec tion)
return
Math.abs(docume nt.selection.cr eateRange().mov eStart('charact er',
-1000000));
}
Comment