lets say I have two DIVS in the page. #news
div and #imp
div respectively.
<div id="news">
Apple is facing a lawsuit for not telling users about the amount of memory required by an upgrade its flagship operating system.
</div>
<div id="imp">
<!-- Empty -->
</div>
Now my requirement is if I select only 'Apple' from the whole sentence then that selected portion gets copied and pasted into div #imp
. And if copied, other portions then get appended.
lets say I have two DIVS in the page. #news
div and #imp
div respectively.
<div id="news">
Apple is facing a lawsuit for not telling users about the amount of memory required by an upgrade its flagship operating system.
</div>
<div id="imp">
<!-- Empty -->
</div>
Now my requirement is if I select only 'Apple' from the whole sentence then that selected portion gets copied and pasted into div #imp
. And if copied, other portions then get appended.
- by selected do you mean when someone highlights a word? – jmore009 Commented Jan 4, 2015 at 19:40
- @jmore009 Thanks for editing. yeah exactly. highlighted word get pasted in other div #imp. – Morez Commented Jan 4, 2015 at 19:43
3 Answers
Reset to default 6Could you do something like this?
$( document ).ready(function() {
$('#news').mouseup(function (e){
text = window.getSelection().toString();
$('#imp').append(text);
});
});
Hope this helps.
JS Bin: http://jsbin./xabije/edit?html,js,output
I would copy the marked text, using this library, into clipboard
https://code.google./p/liveclipboard-jquery/
and use jquery to insert to the div imp
Scott Duke beat me to it but the point was to append so I changed html
to append
and added a space so the words don't jumble together:
$('#news').mouseup(function (){
var selectedText = window.getSelection().toString();
$('#imp').append(" "+ selectedText)
});
FIDDLE
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745098131a4611106.html
评论列表(0条)