defunkt/jquery-pjax — Issue #81: Client-side only implementation bugs
Author: evlapix
Created: 2012-01-12 17:58:54+00:00
State: open

I struggled with why I couldn't get the simplest of test apps working with pjax. It was something like..

**index.html**

```

PJAX!

Replace this..

```

**page.html**

```

Heading!

With this..

```

### Issue 1

The issue turned out to be that pjax does a .find() on the ajax response. There are two issues with this:

1. The elements jquery applies the .find() to might vary per browser: http://api.jquery.com/jQuery/#creating-new-elements
2. .find() searches the _descendants_ of each element in a set (http://api.jquery.com/find/)

In my case #container was in the matched set. Wrapping the #container div in another div fixed this issue.

### Issue 2
The second problem I had was with the text inside of the remote #container div did not get transferred into the current pages #container div.

I solved this issue by changing.. `data = $fragment.children();` to.. `data = $fragment.contents();` in jquery.plax.js

### Summary

1. Make sure your fragment element is not the first element in the body
2. DOM elements with nodeType #text will not be copied over unless wrapped in some other element

I hope to submit a pull request if I can think of a simple way to .find() on the selection, and its children.