I used the following codes posted as the accepted answer in Toggle classname onclick JavaScript
It works great in all browsers, even in old version IE (my project needs this IE support). The only change I made is using this.className instead of myButton.classname in the 2nd line since IE would give error to myButton.classname ('myButton' is undefined).
My question is: even it works, why Eclipse complains by showing a red X beside the last line? If I hover mouse over the red wave under the last } (in the last line), it shows: "Multiple annotations found at this line: - Syntax error, insert "}" to complete MethodBody- Syntax error, insert ")" to complete Expression". This error does occur even if I did not make the above change.
If I add ; after the last } (thinking the function is a part of an executable statement), Eclipse still complains although it continues to work.
Could anyone please give any hints?
document.getElementById('myButton').onclick = function() {
var className = ' ' + this.className + ' ';
if ( ~className.indexOf(' active ') ) {
this.className = className.replace(' active ', ' ');
} else {
this.className += ' active';
}
}