/    Sign up×
Community /Pin to ProfileBookmark

jQuery parse through returned string

Hello,

I’m trying to figure out how to parse through returned data from the jQuery get function. For example, let’s say I have a file called data.html. This file contains this:

[CODE]<div id=”div1″>
<p>Div 1 content</div>
</div>

<div id=”div2″>
<p>Div 2 content</div>
</div>

<div id=”div3″>
<p>Div 3 content</div>
</div>[/CODE]

I then use jQuery AJAX to get that html like this:

[CODE]$.get(‘data.html’, function(data){
var returnedData = data;
$(‘#results’).html(returnedData);
});[/CODE]

This would inject the returned HTML into a div with ID results. That’s all fine and dandy, however I need to target the 3 divs, and place them in different places. For example:

[CODE]$.get(‘data.html’, function(data){
var returnedData = data;
var divOne = $(‘#div1’, returnedData).html();
var divTwo = $(‘#div2’, returnedData).html();
var divThree = $(‘#div3’, returnedData).html();
… do something else with the HTML of each of those Divs.
});[/CODE]

That obviously doesn’t work because the “data” is returning a string (i think?). Is it possible to convert the data into some type of object where I can use the jQuery targeting?

Thanks for any advice!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @cbVision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...