Photoswipe: Uncaught TypeError: Cannot read property 'firstChild' of undefined

Created on 7 May 2015  Â·  11Comments  Â·  Source: dimsemenov/PhotoSwipe

Using your demo markup from CodePen and your scripts installed via Bower I am getting the following error

Uncaught TypeError: Cannot read property 'firstChild' of undefined. on line 66 of photoswipe.js

Most helpful comment

Moving initiating

All 11 comments

Make sure that .pswp element markup is correct (step 2 in the documentation). And make sure that <script> that initializes PhotoSwipe is after .pswp element (or run it in document.ready).

Please provide a reduced test case (isolated example) that reproduces the problem (upload example to your server, or attach .zip'ed project, or use codepen/jsfiddle).

Hi,

I think it was the fact that I had a non-figure element in the collection. A quick check on the nodeName and all is well.

@craigmdennis Currently having the same issue when trying to open Photoswipe through parsing the URL hash. Mind sharing your workaround?

@rppld I can't remember the specifics but — based on my previous comment — where Photoswipe loops through the elements, I skipped to the next element when it wasn't a <figure>.

for(var i = 0; i < numNodes; i++) {
  figureEl = thumbElements[i]; // <figure> element

  // include only element nodes that are `<figure>`s
  if(figureEl.nodeType !== 1 || figureEl.nodeName !== 'FIGURE') {
    continue;
  }

// ...
}

The above is around line 19

I got the same problem. I moved the scripts before the end of </body> tag and solved it. Everything works fine.

photoswipe.min.js:4 Uncaught TypeError: Cannot read property 'firstChild' of undefined

I have same error, please help

@fkamlesh The solution is if you are referring codePen example then, do not forget to add the HTML that's defined from line# 69 to 133 (i.e. EOF)

Moving initiating

Related issues

rafinha90 picture rafinha90  Â·  4Comments

marten-seemann picture marten-seemann  Â·  4Comments

mgk89 picture mgk89  Â·  3Comments

slowaways picture slowaways  Â·  4Comments

jamminjames picture jamminjames  Â·  3Comments