Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unselect a link using jquery

Tags:

jquery

Its a bit difficult to explain, but i will try.

Whenever someone clicks on a anchor link, temporarly a dotted box appears around it. For example, when you click on the stackoverflow logo over the top of this page, it is surrounded by a dotted line temporarily. Because the page gets refreshed, the dotted box goes away.

But with ajax, the link doesnt get refresh, hence the dotted box remains on it. How to remove that dotted box. When you click somewhere on the page the dotted box goes away. How to do it using jquery or any other way.

like image 583
San Avatar asked Dec 03 '09 06:12

San


People also ask

How to disable a href link in jQuery?

JavaScript Code: ready(function(){ $('#button1'). click(function(){ $("a"). removeAttr('href'); }); }); HTML.

How to disable anchor in jQuery?

To essentially disable it, you could likely do: $("a[href='http://www.google.com']").click(function(e) { e. preventDefault(); });

How do I make a link inactive?

Disable a link #remove the href attribute so that it can no longer receive the focus. add a role="link" so that it is always considered a link by screen readers. add an attribute aria-disabled="true" so that it is indicated as being disabled.


1 Answers

To un-select it you can trigger the blur event on the anchor element, for example:

$('a').click(function () {
  this.blur(); // or $(this).blur();
  //...  
});

element.blur() will remove the keyboard focus from the current element.

like image 173
Christian C. Salvadó Avatar answered Oct 30 '22 07:10

Christian C. Salvadó