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, useEffect } = React; function App() { const [linkCount, setLinkCount] = useState(0); useEffect(() => { // Function to count links const countLinks = () => { setLinkCount(document.links.length); }; // Call the countLinks function initially countLinks(); // Add an event listener to update the count if the DOM changes (e.g., due to React re-render) document.addEventListener('DOMContentLoaded', countLinks); // Clean up the event listener when the component unmounts return () => { document.removeEventListener('DOMContentLoaded', countLinks); }; }, []); return ( <div className="container"> <h2 className="heading">React Js Count Number Of Links In Document</h2> <ul className="link-list"> <li className="link-item"><a href="https://www.fontawesomeiocns.com" className="link">Font Awesome Iocns</a></li> <li className="link-item"><a href="https://www.sarkarinaukriexams.com" className="link">Sarkari Naukri Exams</a></li> <li className="link-item"><a href="https://www.tutorialsplane.com" className="link">Tutorials Plane</a></li> </ul> <p className="link-count">Number of links in the document: {linkCount}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #ccc; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); } .heading { font-size: 24px; margin: 10px 0; color: #333; } .link-list { list-style: none; padding: 0; } .link-item { margin: 10px 0; } .link { text-decoration: none; color: #007bff; transition: color 0.3s ease; } .link:hover { color: #0056b3; } .link-count { font-size: 18px; color: #555; margin-top: 20px; } </style> </body> </html>