Making links with no href accessible

后端 未结 2 551
情话喂你
情话喂你 2020-12-18 22:33

A third party script is being used on a site I work on that replaces a few instances of with simple . The links still

2条回答
  •  情深已故
    2020-12-18 23:12

    Whilst it's not very pretty, you can get at all anchors without a href attribute like so, using jQuery;

    $("a:not([href])")
    

    You can then just set the href attribute on those links to "#" and that should make them work again as regular links.

    Here's a working JSFiddle

    Sorry to reply with a jQuery solution...but doing this in regular JavaScript would be much more verbose.

    Another way would be to give the anchors a role and then select them that way:

    $("a[role='link']")
    

提交回复
热议问题