Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Uncaught TypeError: Cannot call method 'appendChild' of undefined #8

Closed
brycenesbitt opened this Issue · 6 comments

4 participants

@brycenesbitt

A simple:
<script src="masonry.min.js"></script>

Or:
<script src="http://vanilla-masonry.desandro.com/masonry.min.js"></script>

Gives me
Uncaught TypeError: Cannot call method 'appendChild' of undefined
at
k = c.getElementsByTagName("body")[0],l = c.createElement("div"); l.style.marginTop = "1%",k.appendChild(l);

Under both Chrome and Firefox on Linux.
Whazzup?
I've got a body tag actually.

This is Vanilla Masonry v1.0.04

@desandro
Owner

I was not able to reproduce this error as described on Chrome for OSX. See http://jsfiddle.net/desandro/aQuxP/ I can't imagine it would be different on Linux, but maybe that's it.

Can you provide an isolated example of this error? Help me help you see https://github.com/desandro/issues-agreement/#readme

@sprclldr

I was also having this problem until I replaced the vanilla masonry min.js with the full masonry min.js from the demos.
Here is a fiddle with the error: http://jsfiddle.net/sprclldr/Gb5Qh/

@desandro
Owner

aaaah, thank you for that :)

Quick fix is to add the vanilla masonry <script> at the bottom of the page, like it is in the demos. Having in the <head> messes up getting the <body> tag.

But this is a legit bug and I'll have to work on a solution.

Note for future Dave: try out fakeBody like Modernizr has

          // After page load injecting a fake body doesn't work so check if body exists
          body = document.body,
          // IE6 and 7 won't return offsetWidth or offsetHeight unless it's in the body element, so we fake it.
          fakeBody = body ? body : document.createElement('body');
@brycenesbitt

If the examples had a /* comment */ about this issue, it would go a long way. There are lots of JS edge cases with script load order, it seems safer not to mess with it and just put it at the bottom.

Your jsfiddle does not fail for me.
This, however, does:

[html]
[head]
[script src="http://vanilla-masonry.desandro.com/masonry.min.js"][/script]
[/head]
[body]
hello
[/body]

'

@desandro desandro was assigned
@roshnit

I am getting this same error. However, I only started to get this error after I tried to integrate it in my WordPress. Any Idea? I am using this to implement it in my code:

header.php

functions.php

wp_enqueue_script('jquery');
wp_register_script('jquery_masonry', get_template_directory_uri(). '/js/masonry.js', array('jquery'), '2.0.110526' );
wp_enqueue_script('jquery_masonry');

@desandro desandro closed this in f647cd9
@desandro
Owner

Hi there. Please update to v1.0.5. This issue should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.