mdbootstrap / material-design-for-bootstrap

Important! A new UI Kit version for Bootstrap 5 is available. Access the latest free version via the link below.
https://mdbootstrap.com/docs/standard/
MIT License
9.34k stars 1.15k forks source link

TypeError: body is null #31

Closed ipepe closed 7 years ago

ipepe commented 7 years ago

I included mdb.js in head and Im getting

TypeError: body is null

Code:

   Waves.init = function (options) {
        var body = document.body;

        options = options || {};

        if ('duration' in options) {
            Effect.duration = options.duration;
        }

        if ('delay' in options) {
            Effect.delay = options.delay;
        }

        if (isTouchAvailable) {
            body.addEventListener('touchstart', showEffect, false);
            body.addEventListener('touchcancel', TouchHandler.registerEvent, false);
            body.addEventListener('touchend', TouchHandler.registerEvent, false);
        }

        body.addEventListener('mousedown', showEffect, false); //TypeError: body is null
    };

Error is marked on last line

marktopper commented 7 years ago

I think it should be added to the end of the body tag.

mdbootstrap commented 7 years ago

Dear ipepe, you are including js in head, due to that when website JS and try to assign body to the variable it cannot do this because this elements wasn't crated yeat (body tag is below head). You have to place your script below body.

ipepe commented 7 years ago

Lol, I know what happend. I just assumed that placing script src tags in head is something normal in modern web development. I guess I will have to patch it myself.