Question

I am using the Magento 2.3.2 Version.

I have set the popup modal but it is not working into the iPhone safari browser. They give the following error:

TypeError: undefined is not an object (evaluating 'elem.nodeName'

Please check below my popup modal code

require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal',
        'owlslider'
    ],
    function(
        $,
        modal
    ) {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: true,
            buttons: []
        };

        var popup = modal(options, $('#popup-mpdal')); //This line Gives error
        $(".country_switcher").on('click',function(){
            $("#popup-mpdal").modal("openModal");
        });
    });

Please give me the solution how to solve this. Thanks in Advance.

Was it helpful?

Solution

Hi Hardik you have solved this problem using below ways

1) By putting your model code inside $( document ).ready()

2) Check the length of your div whether you declared div is available or not.

Try the below code.

require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal',
        'owlslider'
    ],
    function(
        $,
        modal
    ) {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: true,
            buttons: []
        };

        $(document).ready(function(){     
        $(".country_switcher").on('click',function(){ 
            if ($('#popup-mpdal').length != 0) {  
            var popup = modal(options, $('#popup-mpdal'));
            $("#popup-mpdal").modal("openModal");
            }                                
        });
      });
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top