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"> function App() { const removeElementById = (id) => { const element = document.getElementById(id); if (element) { element.remove(); } }; return ( <div className='container'> <h3>React Js Remove Element from DOM</h3> <div id="element1" className="element"> This is Element 1 </div> <button onClick={() => removeElementById('element1')}>Remove Element 1</button> <div id="element2" className="element"> This is Element 2 </div> <button onClick={() => removeElementById('element2')}>Remove Element 2</button> {/* Add more elements and corresponding buttons as needed */} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Style the container */ .container { max-width: 600px; margin: 0 auto; padding: 20px; text-align: center; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } /* Style the elements */ .element { background-color: #f0f0f0; border: 1px solid #ccc; padding: 10px; margin: 10px; border-radius: 5px; transition: transform 0.2s ease-in-out; } .element:hover { transform: scale(1.05); } /* Style the buttons */ button { background-color: #3498db; color: #fff; border: none; padding: 10px 20px; margin: 5px; border-radius: 5px; cursor: pointer; transition: background-color 0.2s ease-in-out; } button:hover { background-color: #2980b9; } /* Optional: Add spacing between elements and buttons */ .element+button { margin-top: 10px; } </style> </body> </html>