1

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 ?

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
Non
  • 8,119
  • 16
  • 63
  • 118

1 Answers1

8

Try to set class attribute instead of setting property className:

this.refs[sideBet].getDOMNode().setAttribute('class', 'animated shake');

hex13
  • 470
  • 3
  • 10