0

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.

Community
  • 1
  • 1
Vercingetorix
  • 253
  • 2
  • 12
  • Are you sure you have the reference to the right element? In other words, are you adding "disabled" to element `li` or `a`? – linstantnoodles Aug 08 '14 at 01:03
  • What have you tried so far? The link you posted doesn't add `.disabled` to anything, and I got the sense that's what you're trying to do. Have you tried `$('#my_link').click(function(){$(this).parent().addClass('disabled');});`? – Nagra Aug 08 '14 at 01:07
  • @linstantnoodles @Nagra Thanks for the comments both. Apologies if I wasn't being specific enough. I was trying to add a class to the `
  • ` element because that's the one that bootstrap supports for disabling. Nagra's solution works correctly when I remove the `.parent()` string. Can't answer my own question for another 8 hours, so feel free to go for it if you'd like the credit Nagra.
  • – Vercingetorix Aug 08 '14 at 01:56