Home » Jquery » javascript – WordPress – HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy

javascript – WordPress – HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have a bug that does not work in WordPress. Someone can help?

Error from console:

HierarchyRequestError: Node cannot be inserted at the specified point
in the hierarchy jquery.js:3

jQuery 3

append

Ga

append

mobileChange /myscript.js:64

/myscript.js:68

I’ve been looking for a solution for several days and I can’t find it. I know this is a little thing for many of you, but I have no idea how to fix it. Can anyone help?

// Menu mobilne
jQuery(document).ready(function(){
  jQuery('#nav-icon').click(function(){
    jQuery(this).toggleClass('open');
    jQuery('#primary-menu').toggleClass('menuOpen');
  });
});
// Koniec menu mobilne


const primaryMenu = jQuery('#primary-menu');
const siteNavigation = jQuery('#site-navigation');

const getSiblings = function (elem) {
    let siblings = [];
    let sibling = elem.parentNode.firstChild;
    let skipMe = elem;
    for ( ; sibling; sibling = sibling.nextSibling )
        if ( sibling.nodeType == 1 && sibling != skipMe )
            siblings.push( sibling );
    return siblings;
}


const liWithChildren = document.querySelectorAll('.menu-item-has-children');
liWithChildren.forEach((element)=>{
   element.children[0].addEventListener('mouseenter', (event)=>{
       if (window.innerWidth >= 992) {
           element.children[0].classList.add('after');
           element.children[1].classList.add('menuOpen');
           event.stopPropagation()
       }
   });
   element.addEventListener('mouseleave', ()=>{
       if (window.innerWidth >= 992) {
           element.children[0].classList.remove('after');
           element.children[1].classList.remove('menuOpen');
       }
   });


    element.children[0].addEventListener('click', (event)=>{
        if (window.innerWidth <= 991) {
           event.preventDefault();
           if ( element.children[1].classList.contains('menuOpen')) {
                window.location.href = element.children[0].getAttribute('href');
           }else {
               element.children[1].classList.add('menuOpen');
               let elementSiblings = getSiblings(element);
               elementSiblings.forEach((sibling)=>{
                   sibling.children[0] ? sibling.children[0].classList.remove('menuOpen') : console.log('brak elementu');
                   sibling.children[1] ? sibling.children[1].classList.remove('menuOpen') : console.log(';)');
               });
           }
        }
    });

});
const mobileChange = ()=>{
    if (window.innerWidth <= 991) {
        primaryMenu.append(jQuery('.search'));
        primaryMenu.append(jQuery('.socialWrapper'));
    }else {
        siteNavigation.append(jQuery('.search'));
        siteNavigation.append(jQuery('.socialWrapper'));
    }
};
mobileChange();
jQuery( window ).resize(function() {
    mobileChange();
});
How to&Answer: