admin管理员组文章数量:1278820
I have a contentEditable iframe with line numbers and text. The line numbers are contained in a div and all text is in a <pre>
-element.
It looks like this:
<body>
<div id="line_numbers">
<div>1</div><div>2</div><div>3</div>
</div>
<pre>
Text
</pre>
</body>
Now, when someone presses Ctrl+A everything is selected, including the line numbers. I would like to change this behaviour to only include the contents of the <pre>
.
I have set up a function that captures Ctrl+A and prevents the default operation. Now, how do I set the selection to contain everything within the <pre>
?
I have a contentEditable iframe with line numbers and text. The line numbers are contained in a div and all text is in a <pre>
-element.
It looks like this:
<body>
<div id="line_numbers">
<div>1</div><div>2</div><div>3</div>
</div>
<pre>
Text
</pre>
</body>
Now, when someone presses Ctrl+A everything is selected, including the line numbers. I would like to change this behaviour to only include the contents of the <pre>
.
I have set up a function that captures Ctrl+A and prevents the default operation. Now, how do I set the selection to contain everything within the <pre>
?
- have you tried $('pre').text() in jQuery? – Reigel Gallarde Commented Jan 23, 2010 at 10:35
- 1 To clarify, Christoffer is trying to select the text in the browser (for copy/paste purposes), not get the text string as a variable. – Mark Bell Commented Jan 23, 2010 at 10:44
2 Answers
Reset to default 8This answer will help you out I think; you should be able to select the pre element using jQuery and pass it into the function supplied:
SelectText($('pre')[0]);
Have you $("#iframe_id").contents().find('pre').text()
?
本文标签: javascriptHow do I select all text contained in ltpregt using jQueryStack Overflow
版权声明:本文标题:javascript - How do I select all text contained in <pre> using jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741273015a2369570.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论