screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/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, useEffect } = React; const App = () => { function updateElement() { const element = document.getElementById('myElementId'); if (element) { element.innerHTML = 'Updated content'; element.style.color = 'red'; } } return ( <div className="container"> <h3>React Js Get Element by id</h3> <div id="myElementId">Initial Content</div> <button onClick={updateElement}>Update Element</button> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { border-radius: 8px; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); padding: 20px; margin: 20px auto; max-width: 600px; text-align: center; } h3 { font-size: 24px; color: #333; } #myElementId { background-color: #f0f0f0; padding: 10px; margin: 10px 0; border: 1px solid #ccc; } button { background-color: #007bff; color: #fff; padding: 10px 20px; border: none; cursor: pointer; } button:hover { background-color: #0056b3; } </style> </body> </html>