The following code is pretty clear, but I ran into a problem linking the click event to the element that was created.
On line 25, you can see the div with the identifier "overlay". Then I set the css properties.
Then, on line 65, I link the click to cause the modality to be hidden. The problem is that it does not work. If I put the div in html, then .click will work as expected.
Any help is appreciated.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Modal</title> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script> <script type="text/javascript"> $(document).ready(function() { </script> <style type="text/css"> .modal{ position:absolute; display:none; z-index:9999; } #rules{ width:600px; height:400px; } #rules p{ background: #fff; margin: 0; padding: 0; } #rules .head{ background: #ddd; text-align: right; padding: 0 10px; height: 30px; } #rules .text{ height: 370px; padding: 0 20px; overflow: auto; } </style> </head> <body> <p><a href="#rules" name="modal">Open Modal</a></p> <div id="rules" class="modal"> <p class="head"><a href="#" class="close">close</a></p> <p class="text"></p> </div> </body> </html>
source share