setTheme = () => { let element = document.getElementById('doc'); // element.setAttribute('class','dark'); element.classList.toggle('dark'); } render() { return ( <div id='doc' class='light'> <h1>Hey</h1> <button id='btn' onClick={this.setTheme}>Click</button> </div> ) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter