Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

360
Vistas
Toggle classname onclick using JavaScript: Why does Eclipse complain?

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';
    }              
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda