Koiw
Koiw

Reputation: 17

Window in jquery

I call window:

$(function(){
$('.link').live('click', function(){
    var perf = $(this).attr('id');
    var action = 'develop';
    var user_id=$('#user_id').val();
    var dataString = 'action='+action+'&perf='+perf+'&user='+user_id;

    $.ajax({
        type: "POST",
        url: "test.php",
        data: dataString,
        cache: false,
        success: function(html){
            $("#work-window").append(html);
        }
    });
});
});

Result in html:

<div id="div-add">
<span id="link-close">`[close]`</div>
</div>

Code for close window when you click on link (#link-close):

$('#link-close').live('click', function(){
    $('#div-add').css('visibility', 'hidden');
});

But here have bug. Window closing only one times. When you reopen the window and trying close, then this is not close. As remove this problem?

Please help me :) And sorry for my English.

Upvotes: 0

Views: 77

Answers (1)

Dmytro Evseev
Dmytro Evseev

Reputation: 11581

You have problem with multiply instanses of elements with the same ids on a page. So when you're executing closing code the second time:

$('#div-add').css('visibility', 'hidden');

it selects the fist one "#div-add" element and do nothing to other instances.

To solve this problem you should remove '#div-add' from page on close (or rewrite your code to use class selector instead of id).

$('#link-close').live('click', function(){
    $('#div-add').remove();
});

Upvotes: 1

Related Questions