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