Click events on label element

I want to show and hide a textarea on mobile to save space. The default behaviour is for the label to focus its associated textarea.

function showHideTextarea() {
if (textarea.style.display == "none") {
  textarea.style.display = null; //remove display: "none" and revert to initial CSS value
  textarea.focus()
}
else {
  textarea.blur();
  textarea.style.display = "none"
}
}

function resizer() {
    if (window.matchMedia("(max-width: 766px)").matches) {
       textarea.style.display = "none"
       textlabel.addEventListener("click", showHideTextarea)
    } 
}

$(document).ready(resizer());

I’ve not been able to get this code to work.

Do you have some associated HTML you can post?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.