2

The full error in the browser console in this

Uncaught TypeError: Cannot set property className of # which has only a getter

I am trying to put a class with Javascript everytime an action happens, this is the code

performClick (sideBet) {
    switch (sideBet) {
    case 'SuitEmUp':
        document.getElementById('SuitEmUp').className = 'animated shake';
        break;

    case 'PerfectPairs':
        document.getElementById('PerfectPairs').className = 'animated shake';
        break;

    default:
        console.log('Sorry, we are out of ' + sideBet + '.');
    }
}

and then changed that code to only this in my Reactjs app

performClick (sideBet) {
    this.refs[sideBet].getDOMNode().className = 'animated shake';
}

and the same error comes up...

HTML

<div ref="sideBetsLeft">

  <svg id="PerfectPairs" onClick={this.performClick.bind(this, 'PerfectPairs')}
       ref="PerfectPairs" className="side-bet" viewBox={viewBoxVal}></svg>

  <svg id="SuitEmUp" onClick={this.performClick.bind(this, 'SuitEmUp')}
       ref="SuitEmUp" className="side-bet" viewBox={viewBoxVal}></svg>

</div>

So, I don't know what is going on here. Any suggestions?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Non
  • 8,409
  • 20
  • 71
  • 123

1 Answers1

11

Try to set class attribute instead of setting property className:

this.refs[sideBet].getDOMNode().setAttribute('class', 'animated shake');
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
hex13
  • 500
  • 5
  • 11