My current task involves toggling the visibility of a textarea's innerHTML based on focus and blur events. The functionality is working as expected, but I have encountered an issue. When I delete the text entered in the textarea, the innerHTML remains hidden even though it still exists within the element. Here are the steps to replicate the issue:
- Enter text inside the textarea
- Select all the text and delete it
- Mouse out from the textarea
- The innerHTML is not visible in the browser
- However, the innerHTML is visible when inspecting elements in the browser
let textarea = document.querySelectorAll("textarea");
for (i = 0; i < textarea.length; i++) {
let innertext = textarea[i].innerHTML;
textarea[i].addEventListener("focus", (e) => {
e.target.innerHTML = "";
})
textarea[i].addEventListener("blur", (e) => {
e.target.innerHTML = innertext;
})
}
<textarea name="" id="" cols="30" rows="10">Test</textarea>