 <p>You can set the <code>data</code> attribute, by using javascript's <code>setAttribute()</code> like so:</p> <pre><code>var theDiv = document.createElement("div"); theDiv.setAttribute('data-x', '4'); theDiv.setAttribute('data-y', '6'); </code></pre> <p>Access them:</p> <pre><code>console.log(theDiv.getAttribute('data-y')); </code></pre> <p>And also access the same with jQuery:</p> <pre><code>$(theDiv).data("x"); </code></pre>