You won’t be able to execute any JavaScript using st.markdown. You will need to use the components api instead.
Note that with the components api, your HTML/JavaScript will get wrapped in an iframe, so be sure to use window.parent.document to reach outside of the iframe where needed.