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

Giving PWA icons transparent backgrounds

RCS 'identification marker' comes in useful

Marking up code examples