How to make an anchor tag refer to nothing?

后端 未结 18 1691
一向
一向 2020-12-12 10:28

I use jQuery, I need to make some anchor tags perform no action.

I usually write it like this:

link

H

18条回答
  •  暖寄归人
    2020-12-12 10:48

    I encountered this issue on a WordPress site. The headers on dropdown menus always had the attribute href="" and the header plugin being used only allowed standard urls. The easiest solution there was just to run this code in the footer:

    jQuery('[href=""]').click(function(e){
        e.preventDefault();
    });
    

    This will prevent blank anchors from doing anything.

提交回复
热议问题