简体   繁体   中英

Dynamically disabling / enabling the links in a Bootstrap dropdown menu on-click

I understand that bootstrap allows a user to disable links within its dropdown menu component simply by adding a class="disabled" into the corresponding <li> tag.

What I'd like to do is write some javascript so that when a user selects the dropdown menu and clicks on a link within it, that link will become disabled. It's in the nature of the dropdown menu to close immediately when a valid link is selected, or when the user clicks outside of the dropdown box. Therefore when the user opens the menu on any subsequent visit, he or she should see all of their previously selected items appearing as disabled.

I've already tried to use the solutions posted in this link: disable a hyperlink using jQuery , but none of them are working for me.

Using Nagra's above javascript solution in this modified form: $('#my_link').click(function(){$(this).addClass('disabled');}); I am able to add the disabled class to each of the <li> elements whenever a user clicks on the <a> embedded within the <li> parent.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM