htmljquery

How do you make an anchor link non-clickable or disabled?


I have an anchor link that I want to disable once the user clicks on it. Or, remove the anchor tag from around the text, but definitely keep the text.

<a href='' id='ThisLink'>some text</a>

I can do this easily with a button by adding .attr("disabled", "disabled");
I successfully added the disabled property, but the link was still clickable.
I don't really care if the text is underlined or not.

Any clue?

When you click on the wrong musician, it should just add "Wrong" and then become unclickable.
When you click and you are correct, it should add "Awesome" and then disable all <a> tags.


Solution

  • I just realized what you were asking for(I hope). Here's an ugly solution

    var preventClick = false;
    
    $('#ThisLink').click(function(e) {
        $(this)
           .css('cursor', 'default')
           .css('text-decoration', 'none')
    
        if (!preventClick) {
            $(this).html($(this).html() + ' lalala');
        }
    
        preventClick = true;
    
        return false;
    });