[jQuery] How to copy the selected text to a textarea on double click


Hello Friends,

I was in a position where i need to edit some part of div block. I need to select some lines from paragraph and than when we double click on it, i need that text and place it to textarea to edit it. To achieve this, when i double click, it was removing the selection of text. Here is a solution i found for this.

<script type="text/javascript">// <![CDATA[
jQuery(function() {
		jQuery(".importedtext").dblclick( function () { 
		$( '.importedtext' ).mouseup( function( ) { 
			var seltext = getSelectedText();
// Get user selection text on page
function getSelectedText() {
    if (window.getSelection) {
        return window.getSelection();
    else if (document.selection) {
        return document.selection.createRange().text;
    return '';
// ]]></script>
<div class="importedtext">Hi.. this is rakshit Patel.</div>
<input id="hid_session" type="hidden" name="hid_session" value="" />
<input id="hid_session_pre" type="hidden" name="hid_session" value="" />

1 Comments on [jQuery] How to copy the selected text to a textarea on double click

  • loss control jobs
    July 18, 2013 at 11:09 am

    This blog was… how do you say it? Relevant!
    ! Finally I’ve found something that helped me. Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *




DHgate Computers
DHgate.com - Computers, Cell Phones & more
  • We find everbuying built in php and use css to control the style.

About Author

PHP Freelancer

PHP Freelancer I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I am here to share all my developing knowledge with you people. For Hire PHP Developer India, contact me.
Follow on twitter: @raxit4u2

Get Free Programming Tutorials:

Become a Fan

Popular Topics

Recent Posts

Most Popular

Recent Comments

Get a Free Quote
Security Question: 3 + 8 = ?