I can reliably get the value of a text type input box using let txtcont = clickedElement.value;.
I use this because some of the text entry boxes do not have an ID attached.
In blogger, for example, if you do the html editing element (plain text where you manually code the html), which is an element like this: <body g_editable="true" hidefocus="true" class="editable " id="postingComposeBox" style="min-width: 0px; width: 653px;" role="textbox" contenteditable="true"><br></body>
You get the value from the the above.
If you switch to “Compose” mode, where the html is displayed as rendered as styled (bold, italic, etc): <body g_editable="true" hidefocus="true" class="editable " id="postingComposeBox" style="min-width: 0px; width: 653px;" role="textbox" contenteditable="true"><br></body>
I do not extract the value, clickedElement.value; is undefined.
These are just normal html element with contenteditable, so you are directly editing HTML. Thus the “value” (which is an input specific property) is the innerHTML property.
It’s definitely a wysiwyg editor being odd, and I have experienced it in both of the wysiwyg modes of Blogger and Wordpress, but they both work fine in the text/manual coding modes.
I realize this question is off-topic, but I wonder this is a serious need of your users. Who is using BBCode (or other coding tags) in a rich text editor?
I was using bbCode in a rich text editor for testing because it is preserved, and not parsed, when one switches back and forth between rich text and code mode.
On edit
Also, there are times where I paste in quoted text while the Blogger editor is in rich text mode using BBCodeXtra, the old extension, and it works.
OK, I have a solution, this will get the data in a rich text field: document.getElementById(document.activeElement.id).contentWindow.document.body.innerHTML
So I put in an if to detect when the get clicked element does not work:
let txtcont = clickedElement.value; //contents of edit box
if (txtcont === undefined) {
txtcont = document.getElementById(document.activeElement.id).contentWindow.document.body.innerHTML;
}
You should be able to shorten document.getElementById(document.activeElement.id) to just document.activeElement since they’re exactly the same reference.