BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi,
I wondered how can i get the font color of selected range from the RichTextEditor’s content.
I tried to use the getRange() method, but it failed.
Could you help me?
document.getElementById('dialogBtn').onclick = (): void => { var sel = window.getSelection(); var range = sel.getRangeAt(0); var pointedTag = range.startContainer.parentNode; console.log(pointedTag.style.color); }; |
Hi Vinitha,
Thank you for your answer.
I checked the answer well, but there is a problem that it doesn't always give the right value.
If change the color partially, i cannot receive the color value from pointedTag.
because the structure of the HTML element changes.
This is also true when applying other properties such as bold and italic.
Is there any other way?
Regards,
Jane
And add,
As above,
Other toolbar items, such as BOLD and ITALIC, are being marked in the toolbar for the selected range.
But the font color is not.
(and I'm using inline mode in my Vue app.)
Is there a possibility that this will be modified?
or Can I know how to get the color value exactly like such as BOLD and ITALIC ?
Regards,
Jane
Hi Vinitha,
Thank you for your answer.
I tried to use the solution, but it has some problems...
So I want to know if there is any possibility to added a method in Syncfusion RichTextEditor that returns the font color of the selected range.
(such as getSelectedHtml, getSelection ...)
Regards,
Jane
Hi Vinitha,
Thank you for your answer.
If the selected range used more than one color, I want to know that.
so I checked when the first and last colors in selected range were different
using 'startContainer' and 'endContainer' in getRange Method.
by comparing those two colors.
But the problem is when the color of the text in the middle area of the selected range.
such as
Is there any solution?
Regards,
Jane
document.getElementById('dialogBtn').onclick = (): void => { var divElem = document.createElement('div'); divElem.innerHTML = document .getElementById('defaultRTE') .ej2_instances[0].getSelectedHtml(); for (var i = 0; i < divElem.childNodes.length; i++) { if (divElem.childNodes[i].tagName == 'SPAN') { console.log(divElem.childNodes[i].style.color); } } }; |