Good day! Faced a problem, JS cannot understand the style in any way and gives an error in console.log every time.
Who knows what the problem may be?

enter image description here

  function closeDialog(fromMask) { if (fromMask === undefined){ fromMask = false; } console.log("TEST mask", fromMask); if (canncellable === true) { $("#mask").fadeOut(300); $(popup_id).fadeOut(300); document.getElementById(popup_id).style.display = "none" } else if(fromMask === false){ canncellable = true; closeDialog(false); } resetIconToHidden() } function resetIconToHidden() { let popupContainer = document.getElementById(popup_id); popupContainer.getElementsByClassName("icon")[0].style.display = "none"; } 

    1 answer 1

    document.getElementById(popup_id) returns undefined . This means that there is no element in the document whose id matches the value that is stored in the variable popup_id .

    First, output the popup_id to the log and make sure that what you expect is there

    Judging by the line

      $(popup_id).fadeOut(300); 

    popup_id contains a value starting with the # character, which in jQuery means that the line contains the element id, and for the getElementById method this symbol is not needed, and the browser thinks that you are looking for an element with id #xxx

    In general, since you already found this element with jQuery, continue to work with it

      $(popup_id).fadeOut(300).css({display: none}); 

    But there is no point in setting display: none . Because jQuery.fadeOut(..) will do it itself at the end of its work

    • Thanks for the answer, I'll try to fix the problem) - Isabella Monza
    • one
      @OlegSevernuy I updated the answer. Re-read it - Anton Shchyrov