Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

362
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!