Remove class not working with MooTools

I'm using the following piece of code in my webpage to change the class of select elements depending on the choice of a radio button.

The part where I add the class works fine but the other (where I remove them) doesn't work. I get no error in the Error console and when I changed my code to have the part that removes the class put another class to the select elements it worked fine.

<script type="text/javascript"> window.addEvent('domready', function(){ $('votconj').addEvent('click', function() { // This works fine $('first_name_conjoint').addClass("validate['required','nodigit']"); $('last_name_conjoint').addClass("validate['required','nodigit']"); $('jj_conjoint').addClass("validate['required']"); $('mm_conjoint').addClass("validate['required']"); $('aaaa_conjoint').addClass("validate['required']"); $('conjoint_regime').addClass("validate['required']"); new FormCheck('formulaire'); }); $('votconj_no').addEvent('click', function() { // This doesn't work ! $('first_name_conjoint').removeClass("validate['required','nodigit']"); $('last_name_conjoint').removeClass("validate['required','nodigit']"); $('jj_conjoint').removeClass("validate['required']"); $('mm_conjoint').removeClass("validate['required']"); $('aaaa_conjoint').removeClass("validate['required']"); $('conjoint_regime').removeClass("validate['required']"); new FormCheck('formulaire'); }); new FormCheck('formulaire'); }); </script> // The radio button <label>Conjoint :</label> <input type="radio" name="votconj" id="votconj" value="oui">oui <input type="radio" name="votconj" id="votconj_no" value="non" checked="checked">non


It doesn't work because the MooTools ".removeClass()" method simple-mindedly jams the class name into the middle of a regex without bothering to escape embedded regex meta-characters.

You can, however, work around the problem by doing the appropriate quoting yourself. In this example, it'd look like this:


Here is a jsfiddle.


  • How can i enable use of background elements when the dialog is appeared?
  • Why doesn't this Dojo 1.9/JS code work in Internet Explorer 7?
  • document.ready like functionality in javascript?
  • squeezebox ajax mootools
  • How can I allow tags through rails 4 sanitize?
  • Removing event listeners on automatically created multiple elements
  • How do you SELECT several columns with one distinct column
  • User messaging system
  • Implicit joins and Where in Doctrine - how?
  • Button text different than value submitted in query string
  • Java: can you cast Class into a specific interface?
  • DomPDF {PAGE_NUM} not on first page
  • Spring Data JPA custom method causing PropertyReferenceException
  • Javascript simulate pressing enter in input box
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • AES padding and writing the ciphertext to a disk file
  • Excel - Autoshape get it's name from cell (value)
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Importing jscolor library in angular 2
  • Upload files with Ajax and Jquery
  • How to pass list parameters for each object using Spring MVC?
  • A cron job substitute?
  • log4net write single file for each call to log.info
  • Proper way to use connect-multiparty with express.js?
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal