B
B
BlackJeff2021-06-26 22:18:12
JavaScript
BlackJeff, 2021-06-26 22:18:12

Why JS code doesn't work on Flask?

Hello, I have a problem with js code not working correctly on Flask.
The js itself works as it should, but if you run the site through Flask, then the js starts to work not as it should, for example, the buttons stop working. For example, here is a simple js function that opens/closes modal windows:

function switchPopup(popupToClose){
    if(popupToClose.style.display == "flex")
        popupToClose.style.display = "none";
    else
        popupToClose.style.display = "flex";
}

The problem here is that modal windows, which are hidden by default, are not set to flex. Js on Flask seems to start to be weird and ignore the else block and simply does not execute it, but if you put some alert or console.log in the else block, then the code starts working for some reason. Again, js itself works.
function switchPopup(popupToClose){
    if(popupToClose.style.display == "flex")
        popupToClose.style.display = "none";
    else
        alert("test");
        popupToClose.style.display = "flex";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lillipup, 2021-06-26
@BlackJeff

I forgot to add curly braces, now your code works like this

if(popupToClose.style.display == "flex"){
        popupToClose.style.display = "none";
}else{
        alert("test");
}

popupToClose.style.display = "flex";

Secondly, display this expression in the console,
popupToClose.style.display
most likely it is always equal to flex, that is, the problem is not in this function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question