Store and retrieve JavaScript arrays into and from HTML data attributes

You could use the HTML escaped characters in the element data attribute to have JSON-like array (encoded are quotes):

<div id="demo" data-stuff="[&#34;some&#34;, &#34;string&#34;, &#34;here&#34;]"></div>

And then in JavaScript get it without any additional magic:

var ar = $('#demo').data('stuff');

See this JSFiddle demo.

However, escaping isn’t necessary. You can do this, instead:

<div id="demo" data-stuff="["some", "string", "here"]"></div>

See this JSFiddle demo.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)