Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's no reason you can't extract the element you want using <code>$.get()</code>.</p> <pre><code>$.get('test.html',function(data) { var posts = $(data).find('#posts'); // If the #posts element is at the top level of the data, // you'll need to use .filter() instead. // var posts = $(data).filter('#posts'); $('#container').append(posts); }); </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>You perhaps didn't notice the code comments above, so I'm going to make it more explicit here.</p> <p>If the <code>#posts</code> element is at the top of the hierarchy in <code>data</code>, in other words if it doesn't have a parent element, you'll need to use <code>.filter()</code> instead.</p> <pre><code>$.get('test.html',function(data) { var posts = $(data).filter('#posts'); $('#container').append(posts); }); </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>Based on the comments below, you seem to need <code>.filter()</code> instead of <code>.find()</code>.</p> <p>The reason is that you're passing in an entire HTML structure. When you do that, jQuery places the direct children of the <code>body</code> tag as the array in the jQuery object.</p> <p>jQuery's <code>.filter()</code> filters against only the nodes in that array. Not their children.</p> <p>jQuery's <code>.find()</code> searches among the <em>descendants</em> of the nodes in the array.</p> <p>Because of this, you're needing to use both. <code>.filter()</code> to get the correct one at the top (<code>#posts</code>) and <code>.find()</code> to get the correct descendant (<code>.next</code>).</p> <pre><code>$(data).filter('#posts').find('.next'); </code></pre> <p>This narrows the set down to only the <code>#posts</code> element, then finds the <code>.next</code> element that is a descendant.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload