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?
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.
Most helpful comment
This works well for me: