Is it an interactions-based modal?
If so, and you’re generating the modal code dynamically, you probably need to re-initialize IX2 so that Webflow can wire up the interactions to your new elements.
Meanwhile I realized that actually I was using page settings and wrote the code there, before closing body -tag. But here right after writing the question, I tested same code within added custom code and it worked. Then, after reading your answer, I added that line to code before end of body, to page settings, and it worked also from there.
Hope these help also others who might have similar issues.