0

In my html I have such code: link and div for jQuery UI Dialog:

 <a data-comment="delete" data-comment-url="<?=Yii::app()->createUrl('comments/delete', ['id' => $comment->id])?>" href="javascript:" ">              
  </a>
 <!-- div with dialog's markup -->
 <div id="commentDelete" class="modal smallDialog" title="УДАЛЕНИЕ">
                            Delete this row &
 <a  class="button142 wa" id="confirmDeleteComment"  style="">Yes</a>
 <a href="javascript:;" onClick="$('#commentDelete').dialog('close');" class="button142 wa">No</a>
                        </div>

In my external js-file I have event handler to catch the click on link:

$(document).on('click', '[data-comment="delete"]', function (evt) {
    evt.preventDefault();

    var data = $.data(document, 'comments'),
        $this = $(this);

    var options = {
        title: 'Delete row?',
        autoOpen: false,
        resizable: false,
        height: 200,
        width: 380,
        show: { effect: 'drop', direction: "up" },
        modal: true,
        draggable: true,
        open: function (event, ui) {

        },
        close: function (event, ui) {
            $("#commentDelete").dialog().dialog('close');
        },
        create: function(event, ui){
            $('#confirmDeleteComment').click(function(){
               console.log("!!!");
            });
        }
    }
    $("#commentDelete").dialog(options).dialog('open');

When I click on link, this event fires well, no problem. But I hope that inside function open() I can assign my action to the first button of div, which used in UI Dialog. Tracing the code, I see that open() fired, click-assigning passed well, without errors, but when I try to click on button - I have no action as I considered - no logs in console.

What am I doing wrong ?

4
  • Why don't you delegate event instead? Commented Jul 31, 2015 at 10:08
  • Becouse to do it I need to google - have no idea what it means. Commented Jul 31, 2015 at 10:13
  • You are already delegating event here: $(document).on('click', '[data-comment="delete"]', function (evt) {...}); so i was thinking you already knew what it means Commented Jul 31, 2015 at 10:17
  • It works. It was good propose, might be I was looking desicion to long. If you write you comment as reply I will mark it as answer. Commented Jul 31, 2015 at 10:28

1 Answer 1

1

You could delegate it to modal div level:

$('#commentDelete').on('click', '#confirmDeleteComment', function () {
    console.log("!!!");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.