Modifying and Disabling Hyperlinks using jQuery

Date Published: 13 April 2012

Modifying and Disabling Hyperlinks using jQuery

I have a simple menu in an ASP.NET MVC application allows a user to take one of several actions after first selecting a resource to work with from a drop down list / select box or textbox. In the case where the user hasn’t yet selected anything (or entered any text), I want the links to be disabled, as I’d rather let the user know the issue on the current dashboard page than have them go to a page without a required parameter and then hit them with an error message about the missing parameter. Instead, I’d like to, in the case of the empty textbox, give the textbox focus and flash some color there so the user (usually me) knows they need to enter something there before proceeding.

You can’t just .disable() a hyperlink or anchor tag using jQuery, nor can you .enable() it. There’s also a bit of magic involved in being able to take the contents of a textbox or select list and stick them into the URL in a link, which I’ll also show here. For my menu, it’s organized inside of an unordered list (

Ardalis

Copyright © 2024