Thursday, November 17, 2011

Hide link or anchor after click with jquery

This is a common need when you provide what I call a naked user interface meaning, well I am waiting for my front end engineer and I provide just the bare minimums so the whole functionality can be used. But this is also a need for complicated user interfaces where sometimes a link is just supposed to trigger something, you want to stay in the page and you do not want the link to be available again (avoiding double submission for example).

So here is the JQuery code that will keep the link text but will change it by just a spanned text:
    // Hide link after click
    $('.hideAfterClickLink').click(function(e) {
     $(this).replaceWith('' + $(this).text() + '')

No comments: