Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

361
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda