Instafeed.js: I just found an error with the instafeed.js

Created on 20 Feb 2015  Â·  3Comments  Â·  Source: stevenschobert/instafeed.js

The script is working flawless as long as <div id="instafeed"></div> exist... But on all pages where <div id="instafeed"></div> do not exist (and the javascript is linked) it causes following error:

Uncaught TypeError: Cannot read property 'appendChild' of null

Seems like it is trying to find elements which do not exist?

programminapi question

Most helpful comment

This works well for me:

if ($('#instafeed').length) {
    feed.run();
}

All 3 comments

Hey @saturday1! You are correct, that error gets thrown when Instafeed can't find an element with the ID instafeed on the page.

However, that error is not generated by just _including_ the javascript file. It's generated when you also try to run Instafeed.js (by doing feed.run()). You can prevent the error by only trying to run it on the pages that have that element.

Hope that helps!

This works well for me:

if ($('#instafeed').length) {
    feed.run();
}

I must note — this error should not be thrown. It should degrade gracefully (or perhaps trigger a warning or console log at worst). The reason for this is AJAX-based websites where some pages have Instafeed and others don't, it becomes a big mess to run and un-run Instafeed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pedrsntana picture pedrsntana  Â·  4Comments

benjamin-hull picture benjamin-hull  Â·  9Comments

masiorama picture masiorama  Â·  5Comments

joshmeares picture joshmeares  Â·  9Comments

heaversm picture heaversm  Â·  3Comments