0

I want to "disable" a Javascript function when my input is focused. Disable might be the wrong term but I simply want to stop a function from working. I have something like the following in mind except the dislable. of course.

input = document.getElementById("input");
if (input.focus()) {
    disable.expand();
}
function expand() {
const gridItems = document.querySelectorAll(".grid-item");
const collapsings = document.querySelectorAll(".collapsing");
for (let i = 0; i < gridItems.length; i++) {
    gridItems[i].addEventListener("mouseenter", () => {
        gridItems[i].style.width = "400px";
        collapsings[i].style.maxHeight = collapsings[i].scrollHeight + "px";
    });
    gridItems[i].addEventListener("mouseleave", () => {
        gridItems[i].style.width = null;
        collapsings[i].style.maxHeight = null;
    });
}

}

Is something like this possible?

W.Tf
  • 1
  • 1
  • 2
    To me this seems to be an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) You don't need to disable a function, just don't call it – Cid Nov 12 '18 at 09:01
  • 1
    You need to provide a little more context: what does the function do? Is it an interval/polling function that runs every x seconds? Is it a promise/async function? What does it do? "Disabling" a function can mean many things, given the ambiguous context. – Terry Nov 12 '18 at 09:01
  • i edited the question – W.Tf Nov 12 '18 at 09:03
  • If you're only changing stylings inside the event handlers, won't a CSS :hover and :focus class be easier? – Shilly Nov 12 '18 at 09:07
  • just add a return statement in your expand function : `if (input.focus()) return;` – scraaappy Nov 12 '18 at 09:09
  • @scraaappy this doesnt work at all... – W.Tf Nov 12 '18 at 09:12
  • @Shilly no because i need the scrollHeight also this has nothing to do with the question – W.Tf Nov 12 '18 at 09:14

0 Answers0