You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changed the title [-]Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '/posts' is not a valid selector.[/-][+]Problem in Dropdown in Bootstrap 4.2.1[/+]on Dec 22, 2018
I had the same issue. What I did to resolve it was looked over the code in the bootstrap.bundle.js from the 4.1.3 version, found the code that caused the issue in 4.2.1 and then replaced it.
Basically in the 4.1.3 version, I went to line 141 which doesn't cause an error.
I then copied that version over to the 4.2.1 version and replaced it at line number 141. The code below is what causes the issue and needs to be replaced with the snippet above.
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;
},
Just make sure to comment out the current code that you're replacing just in case it causes issues and test accordingly.
This was a quick fix and while I checked for other references of the code usage, there's about 12 in the file, it didn't seem to break anything. Note: I haven't tested with other bootstrap features like the Carousel. So make sure to test it with the various features you implement.
Hope this helps.
Reacted by Siavas Firoozbakht, Rob, Antonio Mikulić and Mathieu Smith
My colleague hot-fixed this by adding data attribute data-target to dropdown-toggle and corresponding ID to dropdown-menu. I don't know why, but it works.
See here: https://codepen.io/mattez/pen/romzmO
(I forked and edit not working example from start of this thread)
Why is this starts working? There is no mention in the docs about any data-target in the Dropdown component (only in 'collapse').
@Johann-S , no one of the above solutions function with ASP.NET using Masterpage - and the 4.1.3 version was functioning very well.
See the code below. It functions at the main page (the first page the website runs) but when I entry in a DropDown NAV-Item, the "selection function" really stops.
@Johann-S that seems to work. Unfortunately it only works with one level of dropdown. I was hoping Bootstrap 4 supported that, since it wasn't possible in Boostrap 3, where you had to handle this yourself.
UPDATE: I was able to work around this error by adding attribute target-target="", allthought it copied the CCS styles of the div with id="navbarResponsive"
Activity
[-]Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '/posts' is not a valid selector.[/-][+]Problem in Dropdown in Bootstrap 4.2.1[/+]XhmikosR commentedon Dec 22, 2018
/CC @Johann-S
sts-ryan-holton commentedon Dec 22, 2018
I'm unable to reproduce after upgrading from 4.1.3 to 4.2.1 & seems fine in the docs?
XhmikosR commentedon Dec 22, 2018
@Johann-S: can't we make this a little less strict?
PixemWeb commentedon Dec 22, 2018
I had the same issue. What I did to resolve it was looked over the code in the bootstrap.bundle.js from the 4.1.3 version, found the code that caused the issue in 4.2.1 and then replaced it.
Basically in the 4.1.3 version, I went to line 141 which doesn't cause an error.
I then copied that version over to the 4.2.1 version and replaced it at line number 141. The code below is what causes the issue and needs to be replaced with the snippet above.
Just make sure to comment out the current code that you're replacing just in case it causes issues and test accordingly.
This was a quick fix and while I checked for other references of the code usage, there's about 12 in the file, it didn't seem to break anything. Note: I haven't tested with other bootstrap features like the Carousel. So make sure to test it with the various features you implement.
Hope this helps.
hiro20v commentedon Dec 23, 2018
Probably the same problem is occurring.
Maybe from this commitment
Occurrence code.
mattez commentedon Dec 23, 2018
My colleague hot-fixed this by adding data attribute
data-targetto dropdown-toggle and corresponding ID to dropdown-menu. I don't know why, but it works.See here:
https://codepen.io/mattez/pen/romzmO
(I forked and edit not working example from start of this thread)
Why is this starts working? There is no mention in the docs about any
data-targetin the Dropdown component (only in 'collapse').ankurk91 commentedon Dec 24, 2018
@mattez
You solution works but have one caveat, if user clicks on the same anchor tag again, it does not close (toggle) the dropdown.
ronit-mukherjee commentedon Dec 28, 2018
@mattez
I am seeing a blocking error on the load of the bootstrap.
The error appears in the bootstrap.min.js
Bootstrap Version:- 4.2.1
The error is:-
Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '/c/10013' is not a valid selector.
Johann-S commentedon Dec 28, 2018
A temporary fix would be to add a
data-targetattribute on your link to avoid that error, for example:mattez commentedon Dec 28, 2018
@Johann-S If I understand this well, your fix #27912 will by implemented not earlier then in version v4.3?
24 remaining items
Johann-S commentedon Jan 11, 2019
I made one here: https://codepen.io/Johann-S/pen/WLaqQb?editors=1010
But I forget one thing, the
data-targetelement should contains the selector of the parent dropdown element not, the menu element.see:
DBenS commentedon Jan 14, 2019
@Johann-S , no one of the above solutions function with ASP.NET using Masterpage - and the 4.1.3 version was functioning very well.
See the code below. It functions at the main page (the first page the website runs) but when I entry in a DropDown NAV-Item, the "selection function" really stops.
I tried all the above solutions and all of them I had the same behavior.
Thank you for your attention.
Kindest regards,
David
bjarnef commentedon Jan 14, 2019
@Johann-S that seems to work. Unfortunately it only works with one level of dropdown. I was hoping Bootstrap 4 supported that, since it wasn't possible in Boostrap 3, where you had to handle this yourself.
It seems you have do handle this in Boostrap 4 too something like this:
https://bootsnipp.com/snippets/featured/multi-level-navbar-menu
I don't see the benefits of using the Boostrap dropdown component then, when you have to handle this part of the logic anyway.
Johann-S commentedon Jan 14, 2019
@DBenS I cannot help you more than that, if it works on your first page maybe there is something wrong on your other pages.
Do not hesitate to ask around in the official Slack team or Stack Overflow. See our readme for more details.
@bjarnef there is an issue open here : #27659 about multi level dropdown
emage commentedon Jan 15, 2019
@Johann-S Thank you!
Your updated example solved my issues.
Thanks!
fixed bootstrap 4.2.1 href bug
Update bootstrap to 4.2 and fix js dropdown error
sheilasward commentedon Feb 2, 2019
The problem is that Dropdowns do not work in bootstrap 4.2 unless you have the javascript files at the bottom:
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>yourchoice commentedon Feb 7, 2019
Same for me
DOMException: Failed to execute 'querySelector' on 'Document': '/recettes' is not a valid selector.
O use in href="/recettes" for seo ...
shresthabiswas commentedon Feb 18, 2019
Still not working!

denniseh commentedon Mar 2, 2019
Found that making id's start with a non-numeric character solved the "document.querySelector failed to execute" issue I was getting.
issue with link in navbar
nbinobied commentedon Mar 22, 2019
I'm having similar issue with 4.2.1 when adding Html.ActionLink, it causes the CSS/JS to break from the page. I'd appreciate a way to fix this.
Note: If I added href="#" attribute, it wouldn't load the page and it would cause the link to become /#
I'm getting the following error:
UPDATE: I was able to work around this error by adding attribute target-target="", allthought it copied the CCS styles of the div with id="navbarResponsive"
Johann-S commentedon Mar 23, 2019
Updating your version of Bootstrap to the latest release will fix that (v4.3.1)