I have a button element, which needs to have text which can be modified dynamically. I was having trouble with adding spaces which is when I refered this answer to have a span, which is contenteditable. During this time, I was testing on Chrome and it was working.
However, when I was testing this feature in Firefox, I was not able to insert spaces in the span element. I do not see anything about this online either. Is there anyway I can have this supported on Firefox too?
I should also note that, I am doing this for an Extension that I am building for Chrome and Firefox.
This is what my code looks like:
<!-- HTML --> <button id="editableBtn"> <span id="titleText" contenteditable="false" style="border: solid; border-color: green;">Button</span> </button> <button id="editorBtn">Click me to edit</button> <!-- JS --> <script> var spanText = document.getElementById("titleText"); var editableBtn = document.getElementById("editableBtn"); var editorBtn = document.getElementById("editorBtn"); spanText.addEventListener('keydown', (event) => { console.log("Span keydown = ", event) }) editorBtn.addEventListener('click', (event) => { spanText.contentEditable = "true" }) </script> Firefox Version: 110.0
Google Chrome Verion: 110.0