Wrong use of JavaScript 'replace' function

 I sometimes forget that JavaScript's 'replace' function returns the changed value and does not change the string itself.


I sometimes miss out the first line in code like this:


      targetElement.className =

          targetElement.className.

              replace(/[ ]*vtSettingsRadioButton/g, '');


Here I am removing a CSS class from an HTML element.





Comments

Popular posts from this blog

How a CSS fish animation works

Simple animation spacing out letters in an centred phrase

Giving PWA icons transparent backgrounds