screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const addClassToElement = () => { const element = document.getElementById('myElement'); if (element) { element.classList.add('my-new-class'); } }; return ( <div className='container'> <h3>React Js Add Class to Element by ID</h3> <div id="myElement"> Press the button below to include a class. </div> <button onClick={addClassToElement}>Add Class</button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> /* Styles for the container class */ .container { width: 400px; border: 1px solid #ccc; padding: 10px; margin: 10px; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); margin: 0 auto } /* Styles for the myElement class */ .my-new-class { margin-bottom: 20px; font-size: 18px; font-weight: bold; color: #f44336; background-color: #ccc; padding: 20px; border-radius: 5px; } /* Styles for the button */ button { background-color: #4caf50; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #45a049; } </style> </body> </html>