Use data attribute in function
<p>I have the following HTML:</p>

<pre><code>&lt;select class="select optional" data-minimumresultsforsearch="10" 
  data-query="function (query) {var data = {results: []}, i, j, s; for (i = 1; i &amp;lt; 5; i++) {s = &amp;quot;&amp;quot;; for (j = 0; j &amp;lt; i; j++) {s = s + query.term;} data.results.push({id: query.term + i, text: s});} query.callback(data);}" 
  id="user_default_locale" name="user[default_locale]"&gt;&lt;/select&gt;
</code></pre>

<p>I need to find a javascript function that loops over all the elements like select.  That's the part that I found myself :-)</p>

<pre><code>document.getElementsByTagName('select')
</code></pre>

<p>But now I need to call them all like this:</p>

<pre><code>$("user_default_locale").select2({
            minimumresultsforsearch: 10,
            query: function (query) {
                var data = {results: []}, i, j, s;
                for (i = 1; i &lt; 5; i++) {
                    s = "";
                    for (j = 0; j &lt; i; j++) {s = s + query.term;}
                    data.results.push({id: query.term + i, text: s});
                }
                query.callback(data);
            }
        });
</code></pre>

<p>Anyone know how to do this?</p>

<p>EDIT:</p>

<p>Ok I now have this:</p>

<pre><code>  $('select').each(function(idx, elem) {
  var $elem = $(elem);
  var VarMinimumResultsForSearch = $elem.data('minimumResultsForSearch');
  var VarPlaceholder = $elem.data('placeholder');

  $elem.select2({minimumResultsForSearch: VarMinimumResultsForSearch || undefined, placeholder: VarPlaceholder || undefined});
  });
</code></pre>

<p>And with this it does execute the select2 however not with the params...</p>

<pre><code>&lt;select class="select optional" data-minimumresultsforsearch="1" data-placeholder="JOS" 
  id="user_default_locale" name="user[default_locale]"&gt;
</code></pre>
