Add javascript to views exposed form after ajax submit I've read millions of similar posts on this but I just can't get my head around it. So far I understand that I need to use Drupal.attachBehaviors, and I've tried so many different approaches that I've seen but nothing works. 

Basically I have a jQuery plugin that is styling any select boxes on the site, which works great, apart from on my views exposed form with ajax enabled. The jQuery is literally as simple as $('select').styledSelect(); after including the plugin itself.

EDIT: this is almost there:

      Drupal.behaviors.styledSelect = {
        attach: function() {
          $("select").styledSelect();
        }
      };


But now the ajax call seems to be looping.

EDIT again:

Well it seems to be something to do with the actual plugin, as other Javascript seems to work fine. I'm so close! Here is the plugin:

jQuery.fn.styledSelect = function(options) {
var isFF2 = jQuery.browser.mozilla &amp;&amp; jQuery.browser.version.indexOf('1.8.')==0;
var prefs = {
    coverClass : 'select-replace-cover',
    innerClass : 'select-replace',
    adjustPosition : { top:0, left:0 },
    selectOpacity : 0
    }
if (options) jQuery.extend(prefs,options);
return this.each( function() {
    if (isFF2) return false;
    var selElm = jQuery(this);
    selElm.wrap('&lt;span&gt;&lt;'+'/span&gt;');
    selElm.after('&lt;span&gt;&lt;'+'/span&gt;');
    var selReplace = selElm.next();
    var selCover = selElm.parent();
    selElm.css({
        'opacity':prefs.selectOpacity,
        'visibility':'visible',
        'position':'absolute',
        'top':0,
        'left':0,
        'display':'inline',
        'z-index':1
        });
    selCover.addClass(prefs.coverClass).css({
        'display':'inline-block',
        'position':'relative',
        'top':prefs.adjustPosition.top,
        'left':prefs.adjustPosition.left,
        'z-index':0,
        'vertical-align':'middle',
        'text-align':'left'
        });
    selReplace.addClass(prefs.innerClass).css({
        'display':'block',
        'white-space':'nowrap'
        });

    selElm.bind('change',function() {
        jQuery(this).next().text(this.options[this.selectedIndex].text);
        }).bind('resize',function() {
        jQuery(this).parent().width( jQuery(this).width()+'px' );
        });
    selElm.trigger('change').trigger('resize');
    });
}


EDIT again:

it was the trigger 'change' that was causing the problems - I've changed it to click, and it all seems good woohoo!

As ever, thanks for everyone's wonderful advice.
You'll need to wrap the JS in a Drupal behaviour, so that it is attached after the ajax refresh.

You should also ensure it only runs once

 Drupal.behaviors.styledSelect = {
   attach: function() {
     $('select').once('ss', function() {
       $(this).styledSelect();
     }
   }
 };


That way it won't get 'styled' on every ajax change.