Topic: Accordion and Sidenav
emailoversight priority asked 3 years ago
My MDB SideNav and Accordion dont work, collapsing and returning.
My console has: index.js:181 Uncaught TypeError: Cannot read properties of null (reading 'hasAttribute') at r (index.js:181) at Module.n (event-handler.js:16) at r (bootstrap:19) at bootstrap:83 at universalModuleDefinition:9 at universalModuleDefinition:1
But digging it, it brakes in here: if (jQuery && !document.body.hasAttribute('data-mdb-no-jquery')) {
emailoversight priority answered 3 years ago
Here's the problem. mdb.min.js being loaded at the beginning. I loaded the file at the end of my cshtml and now works fine.
Michał Duszak staff answered 3 years ago
MDB5 3.9.0 is based on vanilla JS. I think it's not problem with jQuery. Have you tried to use the method with event listener?
document.addEventListener('DOMContentLoaded', () => {
// your index.js content or your script here
})
emailoversight priority answered 3 years ago
But it's your index. It comes from /js/mdb/util/index.js Also what's the jquery recommended for the 3.9.0 PRO advanced version ?
Michał Duszak staff answered 3 years ago
Yes. document.body
is null, which is strange. You can try to modify index.js
so that it loads upon the content is loaded. Try this:
document.addEventListener('DOMContentLoaded', () => {
// your index.js content or your script here
})
emailoversight priority answered 3 years ago
I am using version 3.9.0 Pro Advanced. Somehow when I paste my html into Snippet it works fine. My current project uses 2.2.4 jquery.
Could it be the problem ?
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Priority
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 3.9.0
- Device: Any
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No
Michał Duszak staff commented 3 years ago
Could you reproduce this error in a snippet? https://mdbootstrap.com/snippets/