Reputation: 761
When I select some text, it is copied to a textarea. But is it possible if I clic somewhere in a div, it copies all the div ? and not only the text I selected. I have this :
$(document).ready(function() {
$(document).bind("mouseup", function() {
var sel = $.selection('html');
if (sel != '') {
$('#yourTextAreaId').val(sel);
$('#yourDivId').html(sel);
}
});
});
Thank you !
Upvotes: 0
Views: 81
Reputation: 2321
$("#yourDivId").click(function() {
$("#yourTextAreaId").val($(this).html());
});
Upvotes: 0
Reputation: 593
To select div's text try this:
$(document).on('click',function(event){
var text = event.target.innerHTML;
console.log(text);
});
To highlight div you can try this:
$(document).on('click',function(event){
var text = event.target.style.background='yellow';
});
Upvotes: 0
Reputation: 27030
You can use the .text()
property of jquery to get the text content of a node which you can then place into the textarea.
$("yourselector").click(function(){
$("#yourTextAreaId").val($(this).text());
});
Upvotes: 2