Add same class on select form item as selected option

This is a jQuery script for Drupal forms changeing the select form class to the same as the selected option item. I use the change event on select item because Chrome doesn't allow click event on option tags.

<?php
  $script
= '$(document).ready(function() {
                 $("select.bj-status-selector").change(function(){
                       var optClass = $(this).children(":selected").attr("class");
                      $(".bj-status-selector").removeClass().addClass("form-select bj-status-selector " + optClass);
                 });
            });
            '
;
 
 
drupal_add_js($script, 'inline', 'footer');
?>
Knowledge keywords: