i can send now java script code that is only one error please find i can click close…
- User
i can send now java script code that is only one error please find i can click close button not colse
- Assistant
Absolutely, I'd be happy to help you debug your JavaScript code. Please go ahead and send the code snippet you're having trouble with, and I'll do my best to locate and resolve the error regarding the "close" functionality.
- User
<p> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem quam, porro incidunt commodi cum quisquam nostrum in molestiae, accusamus est optio, asperiores aspernatur dolor ipsum omnis itaque aliquam quasi dolorum.</p> <button onclick="close()">Close</button> </div> - Assistant
The issue you are encountering is due to the fact that
closeis a reserved keyword (it's an object function for window, possibly a method of other objects too in some environments) and you can't use it directly, especially in the global context for naming custom functions.You should rename the
closefunction to something else, likeclosePopup. Here's the corrected version of the code:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>alert</title> </head> <body> <button onclick="show()">Show</button> <div class="overlay"></div> <div class="popup"> <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem quam, porro incidunt commodi cum quisquam nostrum in molestiae, accusamus est optio, asperiores aspernatur dolor ipsum omnis itaque aliquam quasi dolorum.</p> <button onclick="closePopup()">Close</button> </div> </body> </html> <style> .overlay { background-color: black; height: 100%; width: 100%; position: absolute; top: 0px; left: 0px; z-index: 1; opacity: 0.8; display: none; } .popup { position: absolute; background-color: white; z-index: 3; color: black; width: 50%; padding: 20px; border-radius: 20px; left: 30%; display: none; } </style> <script> // Overlay and popup var popoverlay = document.querySelector(".overlay"); var popupbox = document.querySelector(".popup"); function show() { popoverlay.style.display = "block"; popupbox.style.display = "block"; } function closePopup() { popoverlay.style.display = "none"; popupbox.style.display = "none"; } </script>