I am using contentededitable on a div and want to add an increase font size button for selected text.
Selected text meaning highlighted with the cursor.
In order to run
document.execCommand('fontsize', false, size);
I need to know the size of the selected text, so I can increase it by 1. How do I get the font size of the currently selected text?
I tried:
var size = document.getSelection().fontSize.toString();
but that was no bueno. I also tried
document.execCommand('increaseFontSize', true, 1)
assuming it would increase it by one integer, but nothing happens, not even an error.
I tried this:
var el = document.getSelection();
var size = window.getComputedStyle(el, null).getPropertyValue('font-size');
But I get the error
Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'