1

jQuery:

$(".close_invoice").confirm({
    title: 'Are you sure to delete it?',
    content: 'Click to Delete if you are sure else click on Close.',
    type: 'red',
    typeAnimated: true,
    buttons: {
        delete: {
            text: 'Delete',
            btnClass: 'btn-red',
            action: function() {
                alert($(this).attr("id"));
            }
        },
        close: {
            text: 'Close',
            btnClass: 'btn-blue',
            action: function() {}
        }
    }
});

HTML:

<button class="btn btn-sm green btn-outline filter-submit margin-bottom close_invoice" id="14" jc-attached="true"><i class="fa fa-times"></i> Close Invoice</button>

Anyone can please tell me Why it not taking the value of attribute ID. How can I get the value of attribute ID? It alerting undefined.

4
  • Please try to trace what "this" object is inside the action function, with console.log(this);. Because it can be a scope problem. And please tell me what ".confirm()" function is, bootbox plugin? Commented Oct 28, 2017 at 5:30
  • this might be referencing to something else. Did you try debugging? Or can you post a snippet/fiddle? Commented Oct 28, 2017 at 5:30
  • you give id="14" in html but in js you have to call like this alert($(this).attr("#14")); . Commented Oct 28, 2017 at 5:32
  • @Tobia .confirm stand for plugin. Commented Oct 28, 2017 at 5:32

1 Answer 1

1

You can't use this selector in function object parameters..You can save this value to a variable, then put it as function paramater object's value

Sign up to request clarification or add additional context in comments.

1 Comment

I think you can use this in function obj parameter, it depends how this function parameter is called! In this case it depends on plugin function call implementation.

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.