Yeah, it turns out that div's don't even support getSelectionRange or createRange like input elements would... so none of the code even executes.
Joy ;) Worth a try anyway. On Apr 7, 1:09 pm, Steel City Phantom <[email protected]> wrote: > are you using jquery? if so, > > http://stackoverflow.com/questions/499126/jquery-set-cursor-position-... > > <http://stackoverflow.com/questions/499126/jquery-set-cursor-position-...>i > have to put some more thought on which event you would have to use to > trigger it. > > in worst case, pull down the jquery code and find the method and see how > they do it. i switched to jquery a long time ago, makes everything much > easier and you have a fairly reasonable guarantee that it will work cross > browser. > > > > On Wed, Apr 7, 2010 at 9:49 AM, egervari <[email protected]> wrote: > > I'm a long time listener. I'm actually the guy that sent him that > > scala question with the name "Huge G. Rection" if you remember that ;) > > That crazy guy from Canada! > > > Anyway... I'm having a problem with JavaScript and I thought since > > this community is way smarter than average communities, I might be > > able to find an answer here. > > > If I'm using editable content divs... is there a way to easily get/set > > the cursor? Gmail makes this look easy, but it's actually not an easy > > problem. > > > My div contains text and other html elements - notably several > > <span>'s. These span's indicate grammar errors and the like. So when > > the person types text into the editor, we have to drop some text nodes > > from the div and replace them with the spans. These spans add those > > nice red squiggles and also provide tooltips indicating how to fix the > > grammar error. > > > Every time I change the contents of the editable div, firefox will > > reset the cursor to the beginning of the content box (annoying!) and > > IE will reset it to the end (not as bad, but still a problem if they > > edit text in the middle). > > > Now, I know there's selection objects and range objects. The problem > > with these is that if the anchor/start nodes they were pointing to are > > deleted, the browser auto-magically points them to other elements of > > the DOM. In Firefox, it's the parent div container. In IE, it's > > something else. > > > Is there another way I can save/restore selection (i.e. cursor) state? > > Or do I have to wrap every word and space character with a <span> tag > > just to avoid deletions? > > > I've spent about 6 hours on this problem, which is actually more than > > it took to build the entire ajax grammar checker. I'm a little > > frustrated and looking for help. > > > I realize this is a JavaScript question, but it's for a Java > > application :) > > > Thanks! > > > -- > > You received this message because you are subscribed to the Google Groups > > "The Java Posse" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<javaposse%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/javaposse?hl=en. > > -- > You want it fast, cheap, or right. Pick two!! -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
