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
  • 14,299
  • 26
  • 93
  • 133

2 Answers2

6

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

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

Aquatic
  • 5,084
  • 3
  • 24
  • 28
1

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

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304