Magento – Uncaught TypeError: Cannot read property ‘nodeName’ of undefined in custom js admin panel

gridmagento-2.1modal-popup

I loaded custom js in head section of grid ui component in order to open a model dialog box when i click a button.

require([
"jquery",
'Magento_Ui/js/modal/modal'
], function($, modal){

var options = {
    type: 'popup',
    responsive: true,
    innerScroll: true,
    title: 'Title',
    buttons: [{
        text: $.mage.__('Proceed'),
        class: '',
        click: function () {
            /* some stuff */
            this.closeModal();
        }
    }]
};
var popup = modal(options,$('#popup-modal'));

$("#print").click(function(){       
....
....}});    

Its throw an following error when page load

jquery.js:3762 Uncaught TypeError: Cannot read property 'nodeName' of undefined

can any one suggest please.

Thanks.

Best Answer

add this code you will resolve the problem

if ($("#popup-modal").length != 0) {

var popup = modal(options, $('#popup-modal')); 

jQuery('#popup-modal').modal('openModal');

}