jquery - setting loses caret position on <pre> element on pressing TAB key -
i have pre
contenteditable="true"
on webpage , trying make append "\t"
when press <tab>
. found other plugins working on <textarea>
.
so, problem when append text <pre>
through jquery, loses caret position. sure losing focus it's not. $("pre").focus()
, nothing.
i tried blur first not practical cause caret return on different position depending on browser. please... :p,
my code here: http://jsfiddle.net/parisk/kprpj/
try using document.execcommand
instead. here’s demo. in short:
$("pre").keydown(function(e){ if (e.keycode==9) { e.preventdefault(); document.execcommand('inserthtml', false, '\t'); } });
Comments
Post a Comment