admin管理员组文章数量:1336304
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.
本文标签: javascriptSelect All contents of a divStack Overflow
版权声明:本文标题:javascript - Select All contents of a div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742258716a2442111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论