jQuery - disable and enable an anchor tag based on condition

后端 未结 6 966
有刺的猬
有刺的猬 2021-01-25 01:10

On page load, I am checking to see if a person is registered. If he is then, I will enable a link otherwise disable the link.

I tried the following , but it doesnt work.

6条回答
  •  别那么骄傲
    2021-01-25 01:33

    use event.preventDefault to prevent anchor tag to work.

    anchor tag doesn't disable on adding attribute disabled

    var status = $('#status').text(); // get text value if it's is span/div/p etc
    if (status == 'Registered') {
        $('#addlink').click(function (e) {
            e.preventDefault();
        });
    } 
    

提交回复
热议问题