javascriptjquery-confirm

appendChild is not a function using $.confirm()


good day, I'm struggling to solve this problem. I spent 1 day to try to solve this problem but no luck for me.

I am trying to append a child inside onContentReady function on $.confirm() but seems doesn't work for me. here is the code

html

<button onclick="btnclick()">click</button>

Javascript

 function btnclick() {
    // body...
    $.confirm({
    title:'test',
    content: '<div class=".confirm_body"> </div>',
    onContentReady:function() {

        var body = this.$content.find('.confirm_body');

        var h3 = document.createElement('h3');
        h3.appendChild(document.createTextNode("child"));
        body.appendChild(h3);
    }
   });
  }

exception

jquery.min.js:2 jQuery.Deferred exception: body.appendChild is not a function TypeError: body.appendChild is not a function
    at Jconfirm.onContentReady (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/:154:8)
    at Array.<anonymous> (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/jquery-confirm-v3.3.0/jquery-confirm.min.js:10:6129)
    at j (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/vendor/jquery/jquery.min.js:2:29568)
    at k (http://localhost/NMSCST_CLINIC_INFORMATION_SYSTEM/assets/vendor/jquery/jquery.min.js:2:29882) undefined
r.Deferred.exceptionHook @ jquery.min.js:2

my code doesn't display the child.

What should I do? Please help


Solution

  • i guess your selector is not correct in this.$content.find('confirm_body'), if confirm_body is id of element then use #, like,

    ...
    onContentReady:function() {
    
        var body = this.$content.find('.confirm_body');
    
        var h3 = document.createElement('h3');
        h3.appendChild(document.createTextNode("child"));
        body.append($(h3)); //make jQuery object for h3 element node & use append
    }
    ...