Bootstrap 4.2.1 - Failed to execute 'querySelector' on 'Document': '[removed]void(0);' is not a valid selector

前端 未结 7 1637
温柔的废话
温柔的废话 2021-02-13 16:54

I am working on a project which I started building on bootstrap 4.0.0. During this project, I had updated bootstrap regulary whenever the new versions ( 4.1.0

7条回答
  •  孤街浪徒
    2021-02-13 17:05

    getSelectorFromElement: function getSelectorFromElement(element) {
                var selector = element.getAttribute('data-target');
                if (!selector || selector === '#') {
                    var hrefAttr = element.getAttribute('href');
    
                    //selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
                    selector = hrefAttr && hrefAttr.indexOf('#') === 0 ? hrefAttr.trim() : '';
                }
    
                return (selector && document.querySelector(selector)) ? selector : null;
            }
    

    this function through error due to document.querySelector not find id like "#home" so if any string not contain # prefix it through error. so replace this:

    selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
    

    from this

    selector = hrefAttr && hrefAttr.indexOf('#') === 0 ? hrefAttr.trim() : '';
    

提交回复
热议问题