JSFiddle - React, Tailwind, and code Playground
by khgriffi259
HTML
<button>
click me
</button>
JavaScript
class Popup {
constructor(title, message, callback) {
this.title = title;
this.message = message;
this.callback = callback;
this.container = document.querySelector('body');
this.result = '';
}
init() {
const popup = `
<div class="popup-wrapper">
<div class="popup bg-white p-1">
<div class="popup-close">X</div>
<div class="popup-content ">
<h2 class="">${this.title}</h2>
<p class="p-1 my-2">${this.message}</p>
<div class="dialogue_buttons my-1">
<button class="btn popup-no" >Cancel</button>
<button class="btn btn-danger my-1 popup-yes" >Start Delete</button>
</div>
</div>
</div>
</div>
`;
this.container.innerHTML += popup;
this.container.querySelector('.popup-no').addEventListener('click', () => this.cancelListener());
this.container.querySelector('.popup-yes').addEventListener('click', () => this.startListener());
}
cancelListener() {
this.result = false;
this.callback();
// if (this.callback !== undefined) {
// this.callback(this.result);
// }
}
startListener() {
this.result = true;
if (this.callback !== undefined) {
this.callback();
}
}
getResult() {
console.log(this.result) ;
return this.result;
}
}
//end of Popup Class
const button = document.querySelector('button');
button.addEventListener('click', e => {
if (e.target.tagName === 'BUTTON') {
const confirmDelete = new Popup(
'Delete',
'This will permanently delete this experience record.',
()=>{
console.log('hello');
let elem = document.querySelector('.popup-wrapper');
elem.parentNode.removeChild(elem);
...