Inspired by the tiber answer, I came up with this that solves the problem in your question. If the text field is a fixed length, what happens if the last letter is not visible at all? What coordination should be reported then? Anyway, this wraps around, expanding the text field endlessly.
// markup <div id="textbox"> <span id="edit" contentEditable></span> <span id="end"></span> </div> <div id="report">x:? , y:?</div> // css #textbox { border: solid black 1px; min-height: 1em; white-space: nowrap; } // javascript $(function() { $('#textbox').click(function() { $('#edit').focus(); }); $('#edit').keypress(function() { var endoff = $('#end').offset(); $('#report').html('x:' + endoff.left + ' , y:' + endoff.top); }); });
The only thing I'm not sure is when keypress fires, if it is before the content has changed, this is a problem. You can get around this by introducing a timeout or perhaps the best solution. Unfortunately, the keyup event doesn't seem to work in contentEditable things (anyway, Firefox 5).
Hope this helps.
source share