nilesh1006
nilesh1006

Reputation: 39

Handle jquery event of one page to another page

I am using jquery to opening a lightbox.I am using two pages for it(Because my requirement is to fetch the lightbox content from another page).Here is my code for fisr page on which i have written the code for opening the lightbox

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
<script>
$(document).ready(function(){
    $('#open').click(function(){
    $("#light").load("light.html");
        $('div.white_content').css("display","block");

    });
    $('#close').click(function(){
        $('div.white_content').css("display","none");
    });
});
</script>

<style>
.white_content {
    display: none;
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    padding: 16px;
    border: 16px solid orange;
    background-color: white;
    z-index:1002;
    overflow: auto;
}
</style>
</head>

<body>
    <p>This is the main content. To display a lightbox click <a href = "javascript:void(0)" id="open">here</a></p>
    <div id="light" class="white_content"></div>
</body>
</html>

And here is My Code Where the content for lightbox is

the page in light.html

<div>Hello this is sandeep<br />
        Widevision technology
 <br />indore <a href = "javascript:void(0)" id="close">Close</a>
</div>

The above code is Working fine though.The problem is in closing the lightbox.Since i have fetch the lightbox content from another page(light.html).My close event code is as you can see above written on index.html

$('#close').click(function(){
        $('div.white_content').css("display","none");
    });

The above code is not working but if i move above code to light.html ,it will work.But i want to make it work from index.html.AS the open event is working from this page why not close event?

Upvotes: 0

Views: 582

Answers (1)

Manuel van Rijn
Manuel van Rijn

Reputation: 10305

Try changing .click(function() { into .live('click', function() {

see jquery live api doc

Upvotes: 1

Related Questions