I want to show some buttons if someone select text in a editable area - like this:
So, I think I have to use <div contenteditable="true">
instead of <textarea>
But to be honest I have no idea how to append the div
Questions:
JsFiddle: http://jsfiddle.net/hA7Zn/
Thanks for any hints!
Use the insertAdjacentText() method to append text to a div element, e.g. container. insertAdjacentText('beforeend', 'your text here') . The method inserts a new text node at the provided position, relative to the element it was called on.
Differences from Node.appendChild() : Element.append() allows you to also append string objects, whereas Node.appendChild() only accepts Node objects. Element.append() has no return value, whereas Node.appendChild() returns the appended Node object.
Check this Demo for getting selected text,
Event selectstart is fired in case of selection
$(function () {
$('div').on('selectstart', function () {
console.log('..');
$(document).one('mouseup', function() {
alert(this.getSelection());
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With