 <p>Generate array of values of <code>data-x</code> and <code>data-y</code> values using <strong><a href="http://api.jquery.com/map/" rel="nofollow"><code>map()</code></a></strong> and <strong><a href="http://api.jquery.com/get/" rel="nofollow"><code>get()</code></a></strong>. Then use <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min" rel="nofollow"><code>Math.min</code></a></strong> and <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max" rel="nofollow"><code>Math.max</code></a></strong> with <strong><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply" rel="nofollow"><code>apply()</code></a></strong> to get maximum and minimum value from array.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>// generate array of `data-x` attribute var arr1 = $('[data-x]').map(function() { return $(this).data('x'); }).get(); // generate array of `data-y` attribute var arr2 = $('[data-y]').map(function() { return $(this).data('y'); }).get(); console.log( Math.min.apply(Math, arr1), Math.min.apply(Math, arr2), Math.max.apply(Math, arr1), Math.max.apply(Math, arr2) )</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="container"&gt; &lt;div class="right" data-x="1" data-y="1"&gt;&lt;/div&gt; &lt;div class="right" data-x="2" data-y="1"&gt;&lt;/div&gt; &lt;div class="right" data-x="3" data-y="1"&gt;&lt;/div&gt; &lt;div class="right" data-x="4" data-y="1"&gt;&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>