I'm having trouble selecting all contents of the div. Here's a demo:
/
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
I'm having trouble selecting all contents of the div. Here's a demo:
http://jsfiddle/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
Share Improve this question edited Jan 10, 2012 at 12:08 Jürgen Paul asked Jan 10, 2012 at 11:53 Jürgen PaulJürgen Paul 15k28 gold badges96 silver badges136 bronze badges 9- 1 it works good for me. Both lines are selected ! – Snake Eyes Commented Jan 10, 2012 at 11:55
- its selecting all the contents fine..! – Sudhir Bastakoti Commented Jan 10, 2012 at 11:55
- please include all necessary code, to understand you question, in your question as well. – Yoshi Commented Jan 10, 2012 at 11:56
- Works for me in FF 9.0.1 and IE9, but not in Chrome 16. – Anthony Grist Commented Jan 10, 2012 at 11:56
- Its selecting all in IE 7 but not in Chrome, please help! – Pratik Commented Jan 10, 2012 at 11:56
2 Answers
Reset to default 6It seems that removing webkit specific calls to setBaseAndExtent fixes issue in latest Chrome
http://jsfiddle/KcX6A/309/
I believe you need to use innerHTML (or was it outerHTML) to get the entire text.