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

前端 未结 7 1541
温柔的废话
温柔的废话 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:08

    Here is the solution that works for me

    Snippet from Bootstrap 4.1.3

    getSelectorFromElement: function getSelectorFromElement(element) {
        var selector = element.getAttribute('data-target');
    
        if (!selector || selector === '#') {
          selector = element.getAttribute('href') || '';
        }
    
        try {
          return document.querySelector(selector) ? selector : null;
        } catch (err) {
          return null;
        }
    },
    

    Replace it from Bootstrap 4.2.1

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

    Thanks to PixemWeb github solution

    For more info here is the link https://github.com/twbs/bootstrap/issues/27903#issuecomment-449600715

提交回复
热议问题