r/learnjavascript • u/Upset-Guide4866 • Feb 16 '26
I am new to programming, I want to make an electron app, and now I am working on the front -end of the app, and here is a screenshot
This feels very sloppy and very bad, I think you should not be using classes like this, if my feelings are right, then what is an alternative approach?
const main = document.getElementById('main_section');
const popups = document.getElementById('popups');
const addInvoiceButton = document.getElementById('add_invoice');
const parser = new DOMParser();
class Invoice {
constructor() {
const specifications = `
<div class="invoice" id="invoice"
style="
width: 700px;
height: 400px;
background-color: black;
position: absolute;
left: 40%;
top: 30%;
display: flex;
">
<button type="button" name="button" id="cancel_invoice"
style="
">
cancel
</button>
</div>
`;
const execution = parser.parseFromString(specifications, 'text/html');
popups.replaceChildren(...execution.body.childNodes);
const invoiceArea = document.getElementById('invoice');
const invoiceCancelButton = document.getElementById('cancel_invoice');
invoiceCancelButton.addEventListener("click", ( () => {
invoiceArea.style.display = "none";
}));
}
}
addInvoiceButton.addEventListener("click", ( () => {
new Invoice();
}));