Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:56:33+00:00 2026-06-17T08:56:33+00:00

I am loading some html from a remote source via the jQuery $.ajax() method.

  • 0

I am loading some html from a remote source via the jQuery $.ajax() method.

Before I insert the html into the DOM, I want to chop it up into three pieces and insert each individual part into a particular area of my DOM.

For example, lets assume I load the following content via the $.ajax() function:

<div class='first'>First</div>
<div class='second'>Second</div>
<div class='third'>Third</div>

And want to insert it into this page connected to the DOM:

<div class='firstHome'>Some content I want replaced.</div>
<div class='secondHome'>More content to replace.</div>
<div class='thirdHome'>Final location for content.</div>

which would result in:

<div class='firstHome'><div class='first'>First</div></div>
<div class='secondHome'><div class='second'>Second</div></div>
<div class='thirdHome'><div class='third'>Third</div></div>

How can I achieve that with jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:56:34+00:00Added an answer on June 17, 2026 at 8:56 am

    Pick the content out of the returned html and append it.

    var $frag = $(returnedhtml);
    
    $(".firstHome").html($frag.find(".first").addBack(".first"));
    $(".secondHome").html($frag.find(".second").addBack(".second"));
    $(".thirdHome").html($frag.find(".third").addBack(".third"));
    

    The above code will only work in jQuery 1.9+, for previous versions, use this:

    var $frag = $(returnedhtml);
    
    $(".firstHome").html($frag.find(".first").andSelf().filter(".first"));
    $(".secondHome").html($frag.find(".second").andSelf().filter(".second"));
    $(".thirdHome").html($frag.find(".third").andSelf().filter(".third"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading some HTML from a file via AJAX, trying extra a block from
I am loading some html via $.get() into a Jquery-dialog-popup. Upon clicking a link
Using jQuery 1.7.1, I am loading some HTML fragments via AJAX that are injected
I'm loading HTML from an AJAX request, and some img tags in it. I
I'm loading some HTML via Ajax with this format: <div id=div1> ... some content
I am having some strange problems loading content from another XHTML page via jQuery.
I'm loading from DB some html (using ajax post request), it looks like: <div
I'm loading HTML-formatted content into my app from a web service, then plugging that
I am loading some text from a database via $.post. Sometimes on page load
I'm moving my site from HTML/CSS into CodeIgniter. Have some experience with PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.