Operator precedence with JavaScript’s ternary operator
Use: h.className = h.className + (h.className ? ‘ error’ : ‘error’) You want the operator to work for h.className. Better be specific about it. Of course, no harm should come from h.className += ‘ error’, but that’s another matter. Also, note that + has precedence over the ternary operator: JavaScript Operator Precedence