title: Applying JQuery plugin to new elements inserted into DOM through AJAX using each()
body: <p>I'm using the JQuery plugin <code>customSelect()</code> <a href="http://adam.co/lab/jquery/customselect/" rel="nofollow">http://adam.co/lab/jquery/customselect/</a> to style dropdown boxes.</p>
  
  <p>If I initialize the script more than once on the same elements, they cease to work.  I need to figure out a way to only initialize the plugin on newly created elements inserted into the DOM through AJAX.</p>
  
  <p>So, I initialize it on all drop downs (the desired effect) -</p>
  
  <pre><code>$('select').customSelect();
  </code></pre>
  
  <p>and elements that I select this plugin work for are given a class of "hasCustomSelect", like so</p>
  
  <pre><code>&lt;select class="hasCustomSelect"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>but if I initialize twice - </p>
  
  <pre><code>$('select').customSelect();
  $('select').customSelect();
  </code></pre>
  
  <p>it will literally stop working. </p>
  
  <p>So, in my AJAX request, I have it initializing on elements WITHOUT that class, but it doesn't seem to be working.  Here is the AJAX -</p>
  
  <pre><code>$.ajax({
      type: 'POST',
      url: 'wp-content/themes/themetitle/functions/get-child.php',
      data: { childID : theID, URL : theURL, classlevel : classlevel },
          beforeSend:function() {
  
          },
          success:function(data) {
              $('#makesort').append(data); 
              makesort(); 
              $.each('select', function() {
                  if( $(this).hasClass('hasCustomSelect') ) {
                      //DO NOTHING!  
                  } else {
                      $(this).customSelect(); 
                  }
              });
          },
          error:function() {
  
          }   
      }); 
  </code></pre>
  
  <p>So, the thought I had was after the <code>data</code> is appended to my <code>div</code>, I'll go through each <code>&lt;select&gt;</code> element, determine if it already contains the class <code>hasCustomSelect</code>, and if not, then initialize the plugin for this element.</p>
  
  <p>This doesn't seem to have the desired effect, however, and in fact, it's producing an error.  There are probably several ways to see if a plugin is already applied, but I thought checking to see if the default class that's added is there would be sufficient.  </p>