/    Sign up×
Community /Pin to ProfileBookmark

How do I get the text in the div with javascript / Jquery?

Hello,

I want to get the text inside the div tag on the page I am running with ajax

This is the div tag: `<div style=”display:none;”>{“a”:”11″,”b”:”22″,”c”:”33″}</div>`

“`
$.ajax({


success: function(data){

var JSONString = “[” + data + “]”;
var JSONObject = JSON.parse(JSONString);
var result = “Option A ” + JSONObject[0][“a”] + “Option B ” + JSONObject[0][“b”] + “Option C ” + JSONObject[0][“c”];
}
“`

I want to get json_array in div

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gecekuleauthorFeb 04.2021 — I found Solution

<div id="json_array" style="display:none;">{"a":"11","b":"22","c":"33"}</div>

ajax

var json_array = $(data).filter("#json_array").html();

var JSONString = "[" + json_array + "]";

Copy linkTweet thisAlerts:
@daveyerwinFeb 04.2021 — ``<i>
</i>&lt;div style="display:none;"&gt;{"a":"11","b":"22","c":"33"}&lt;/div&gt;
&lt;script&gt;
obj = (JSON.parse(document.querySelector('div').innerHTML));
alert("Option A = " + obj.a + ",Option B = " + obj.b + ",Option C = " + obj.c);
&lt;/script&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@siddhi_patelFeb 08.2021 — Hello,

I am also finding a solution like the above answers
``<i>
</i>&lt;div id="json_array" style="display:none;"&gt;{"a":"11","b":"22","c":"33"}&lt;/div&gt;
ajax
var json_array = $(data).filter("#json_array").html();
var JSONString = "[" + json_array + "]";<i>
</i>
``
Copy linkTweet thisAlerts:
@VITSUSAFeb 08.2021 — @siddhi_patel#1627707 This is a really good solution, it's working :)
Copy linkTweet thisAlerts:
@marksmith121Feb 11.2021 — Great solution,Thanks
×

Success!

Help @gecekule 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 4.25,
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,
)...