I am trying to implement a functionality that will allow users to navigate to the href of a drop-down item anchor element on mobile devices in a second click. However, I only want this to happen if the list item currently has an βopenβ class, indicating that the link has been clicked once. I tried the following:
$('.dropdown').on('hide.bs.dropdown', function () { if ($(this).hasClass('open')) { window.location = $(this).find('a.dropdown-toggle.visible-sm').href(); } });
and
$('.dropdown.open').on('hide.bs.dropdown', function () { window.location = $(this).find('a.dropdown-toggle.visible-sm').href(); });
but both allow users to navigate to any other href dropdown without expanding the drop-down list. Having studied several more articles, I found several articles that say that when adding a class dynamically, you must use event delegation to be able to refer to the dynamically added class. I tried this:
$(document).on('click', 'li.open', function(){ window.location = $(this).find('a.dropdown-toggle.visible-sm').href(); });
but he does the same as before.
source share