jQuery - disable and enable an anchor tag based on condition

后端 未结 6 1029
有刺的猬
有刺的猬 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:39

    If you really want to remove the link you can use jquery unwrap method.

    $("yourlinkselector").contents().unwrap();
    

    This will remove the link. To add it back again you might have to put the link text into a span, give it a name and use .wrap to wrap it around your content.

    Working example can be found here: http://jsfiddle.net/Elak/hrvPj/2/

    // remove the link
    $(".link").contents().unwrap().wrap("")
    
    // add the link again and remove the temp span
    $(".oldLink").contents().unwrap().wrap("");
    

提交回复
热议问题