6

I'm having trouble selecting all contents of the div. Here's a demo:

http://jsfiddle.net/KcX6A/304/

It's selecting only the first line of texts, the other lines are ignored. How can I fix this?

EDIT:

By browser is google chrome

SECOND EDIT:

Too bad i'd be answering my own question. But here i've got it to work on Google Chrome:

I've replaced

selection.setBaseAndExtent(text, 0, text, 1); 

with

selection.selectAllChildren(text);

and it worked like a charm! Please guys inform me if it works with other browsers as well.

Working Demo

Jürgen Paul
  • 13,381
  • 25
  • 90
  • 131

2 Answers2

6

It seems that removing webkit specific calls to setBaseAndExtent fixes issue in latest Chrome

http://jsfiddle.net/KcX6A/309/

Aquatic
  • 4,999
  • 3
  • 22
  • 28
1

I believe you need to use innerHTML (or was it outerHTML) to get the entire text.

Sachin Kainth
  • 43,353
  • 79
  • 196
  • 295