Anatole
Anatole

Reputation: 144

How to get value of an objet in an attribute?

Hope you're well. I need your help today.

I've got on my page a which contains attributes. One of these, named data-params, contains an object. In this object we've got a lot of data and I want to get only one value. I tried to use Object.keys OR element.attributes but it doesn't work. I really don't know how and where to search. It seems this object looks like JSON.

By the way thanks a lot by advance for your help and happy coding :)

PS : Here the code of the :

<div id="wpws-live" data-params="{&quot;cache_url&quot;:&quot;https:\/\/www.ecommerce-nation.fr\/wp-content\/plugins\/wpwebinarsystem\/cache\/webinar_808227d5-f2e7-480d-b438-19f2d0e6feb8_v2.json&quot;,&quot;secure_room_name&quot;:&quot;96269b8f-3ce6-47f2-8c64-92e62291799a&quot;,&quot;secure_room_key&quot;:&quot;e2324107-c6b6-42a8-8a79-a5bdfc26ac32&quot;,&quot;reduce_server_load&quot;:false,&quot;webinar_time_in_seconds&quot;:3465657,&quot;webinar_start_time&quot;:1591194600,&quot;duration&quot;:3600,&quot;timezone_offset&quot;:120,&quot;attendee&quot;:{&quot;id&quot;:477,&quot;name&quot;:&quot;blablablo&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;is_team_member&quot;:true},&quot;translations&quot;:{&quot;webinarSummaryStartingTimer&quot;:&quot;Commence \u00e0&quot;,&quot;webinarSummaryStartWebinar&quot;:&quot;Lancer le webinar&quot;,&quot;webinarSummaryStopBroadcasting&quot;:&quot;Stopper le webinar&quot;,&quot;webinarSummaryLogout&quot;:&quot;Quitter le webinar&quot;,&quot;webinarTimerDays&quot;:&quot;jours&quot;,&quot;webinarTimerHours&quot;:&quot;heures&quot;,&quot;webinarTimerMinutes&quot;:&quot;minutes&quot;,&quot;webinarTimerSeconds&quot;:&quot;secondes&quot;,&quot;webinarTabsPeople&quot;:&quot;Explorateurs&quot;,&quot;webinarChatEmpty&quot;:&quot;Personne n'a encore parl\u00e9... Lancez la conversation !&quot;,&quot;webinarChatPlaceholder&quot;:&quot;Appuyez sur Entrer pour envoyer votre message&quot;,&quot;webinarChatMenuDelete&quot</div></div></div></div></div></div></div></div></div></main></div>

Upvotes: 0

Views: 59

Answers (1)

Carsten Massmann
Carsten Massmann

Reputation: 28196

The data-params string seems to be incomplete. I did some "repair work" on it and managed to process it as shown below:

let d=document.querySelector("#wpws-live"),jsn=d.dataset.params,
    o=JSON.parse(jsn);
d.textContent=o.attendee.email;  // display a single property in the div
console.log(o);                  // list the whole object with all its properties
.as-console-wrapper { max-height: 80% !important;}
<div id="wpws-live" data-params="{&quot;cache_url&quot;:&quot;https:\/\/www.ecommerce-nation.fr\/wp-content\/plugins\/wpwebinarsystem\/cache\/webinar_808227d5-f2e7-480d-b438-19f2d0e6feb8_v2.json&quot;,&quot;secure_room_name&quot;:&quot;96269b8f-3ce6-47f2-8c64-92e62291799a&quot;,&quot;secure_room_key&quot;:&quot;e2324107-c6b6-42a8-8a79-a5bdfc26ac32&quot;,&quot;reduce_server_load&quot;:false,&quot;webinar_time_in_seconds&quot;:3465657,&quot;webinar_start_time&quot;:1591194600,&quot;duration&quot;:3600,&quot;timezone_offset&quot;:120,&quot;attendee&quot;:{&quot;id&quot;:477,&quot;name&quot;:&quot;blablablo&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;is_team_member&quot;:true},&quot;translations&quot;:{&quot;webinarSummaryStartingTimer&quot;:&quot;Commence \u00e0&quot;,&quot;webinarSummaryStartWebinar&quot;:&quot;Lancer le webinar&quot;,&quot;webinarSummaryStopBroadcasting&quot;:&quot;Stopper le webinar&quot;,&quot;webinarSummaryLogout&quot;:&quot;Quitter le webinar&quot;,&quot;webinarTimerDays&quot;:&quot;jours&quot;,&quot;webinarTimerHours&quot;:&quot;heures&quot;,&quot;webinarTimerMinutes&quot;:&quot;minutes&quot;,&quot;webinarTimerSeconds&quot;:&quot;secondes&quot;,&quot;webinarTabsPeople&quot;:&quot;Explorateurs&quot;,&quot;webinarChatEmpty&quot;:&quot;Personne n'a encore parl\u00e9... Lancez la conversation !&quot;,&quot;webinarChatPlaceholder&quot;:&quot;Appuyez sur Entrer pour envoyer votre message&quot;}}">the div</div>

Upvotes: 1

Related Questions