Reputation: 258
I have a console.log
inside a function in an IIFE that is not working (doesnt show the "id").
The console.log
outside the IIFE is working correctly.
I can't find where is the problem.
(function () {
document.addEventListener("DOMContenLoaded", () => {
const paramsURL = new URLSearchParams(window.location.search);
const customerId = parseInt(paramsURL.get("id"));
console.log(customerId);
});
})();
console.log(window.location.search)
Upvotes: 0
Views: 62
Reputation: 2054
I suspect the problem is related to a typo. It is DOMContentLoaded
not DOMContenLoaded
.
(function () {
document.addEventListener("DOMContentLoaded", () => {
const paramsURL = new URLSearchParams(window.location.search);
const customerId = parseInt(paramsURL.get("id"));
console.log(customerId);
});
})();
console.log(window.location.search)
Upvotes: 2
Reputation: 2378
Instead of using an IIFE, this would simply work.
document.addEventListener("DOMContenLoaded", () => {
const paramsURL = new URLSearchParams(window.location.search);
const customerId = parseInt(paramsURL.get("id"));
console.log(customerId);
});
Upvotes: 1