Reputation: 331
I am trying to find a way to populate the content of multiple div tags with HTML results I get from a single AJAX response.
Example:
Does jQuery help to solve this, how can I handle this? I am thinking about just adding the whole response to div_page and the copying the data, then removing the handled elements.
Upvotes: 1
Views: 501
Reputation: 964
Lets say your response looks like
<div id='div1'>foo</div><div id='div2'>bar</div><div id='div3'>Foobar</div>
You can parse the response using .filter() and access the inner html using .html()
//Assuming var response is the html from the ajax request
let div1 = $(response).filter("#div1").html();
let div2 = $(response).filter("#div2").html():
let div3 = $(response).filter("#div3").html();
I've made an example for you here https://codepen.io/anon/pen/QqJLee
Upvotes: 2
Reputation: 689
Yes, you easily do that with jQuery.Assuming the resp_1 is html then you can do something like below.
$("#div_1").html(resp_1);
more help over here
Upvotes: 1