2

I'm trying to move the cursor of a content editable div to the end of the line. By default, it goes to the beginning of the line.

I'm using:

var r = $("#mydiv").createTextRange(); 
r.moveStart("character", l); 
r.moveEnd("character", l);      
r.select();

The error I get:

Uncaught TypeError: Object [object Object] has no method 'createTextRange'

I've seen this question posted around, but I still can't seem to perform createTextRange(). Any suggestions?

bdev
  • 2,060
  • 5
  • 24
  • 32
  • I'm not sure exactly what you're asking, but does this answer the question? http://stackoverflow.com/a/4238971/96100 – Tim Down Jul 02 '12 at 15:58

2 Answers2

0

http://help.dottoro.com/ljouisvm.php

The createTextRange() method is no longer supported by most browsers.

You could replace that div with a styled textarea or place one inside of the div.

Max Hudson
  • 9,961
  • 14
  • 57
  • 107
0

Here is a jQuery plugin you can give a try.

A small cross-browser JavaScript library for obtaining and manipulating selections within and HTML elements.

http://code.google.com/p/rangyinputs/

scusyxx
  • 1,226
  • 1
  • 8
  • 9