I want to stop code execution in first class until button, which is created in second class, is clicked. How can I achieve this?
class First {
constructor() {
const second = new Second()
console.log('Print this ONLY when button from Second class is clicked')
}
}
class Second {
constructor() {
const button = document.createElement('button')
button.innerText = 'Button from second class'
button.addEventListener('click', () => {
// Some kind of callback?
console.log('Clicked')
})
document.body.appendChild(button)
}
}
function myFunction() {
new First()
}
<html>
<button onclick="myFunction()">Click me!</button>
</html>