Select All content div

I'm having trouble selecting the entire contents of a div. Here is a demo:

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

It selects only the first line of texts, the remaining lines are ignored. How can i fix this?

EDIT:

The browser contains google chrome

SECOND EDIT:

It is a pity that I would answer my question. But here I have to work in Google Chrome:

I replaced

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

from

 selection.selectAllChildren(text); 

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

Working demo

+6
source share
2 answers

Removing the specific webkit calls for setBaseAndExtent seems to fix the issue in the latest Chrome

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

+6
source

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

+1
source

Source: https://habr.com/ru/post/905611/


All Articles