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?
Pick the content out of the returned html and append it.
The above code will only work in jQuery 1.9+, for previous versions, use this: