Tuesday, September 1, 2009

[jQuery] Re: - issue closing element modal

> I need a modal window within an element on my page and the BlockUI
> plugin works
> great for this.  The problem is that I want a button on the blockUI
> message that will close the block.  I can't seem to get this to work.
> If I put the button elsewhere on the page, it works to close the
> block, but whenever the button is actually in the block div, it
> doesn't work.  A close button in the block div works fine for full UI
> blocking, just not for element blocking.
> Is this possible?  Any ideas would be much appreciated.
> Thanks.
> -Halsey
>
> ====
> code snippet
>
> $('#paneRecordHeader').click(function() {
>         $('#paneRecord').block({
>                 message: 'Legal Mumbo Jumbo <input type="button"
> id="btnAgree"
> value="I Agree" />'</p>',
>                 css: { border: '1px solid #a00' }
>         });
>
> });
>
> $('#btnAgree').click(function() {
>          $('#paneRecord').unblock();
>  });


You need to move that click handler so that it is bound when the
element exists in the DOM:

$('#paneRecordHeader').click(function() {
$('#paneRecord').block({
message: 'Legal Mumbo Jumbo <input type="button" id="btnAgree"
value="I Agree" /></p>',
css: { border: '1px solid #a00' }
});
$('#btnAgree').click(function() {
$('#paneRecord').unblock();
});
});


Alternatively, you could use the 'live' method.

No comments: