Reputation: 413
Am trying to disable a hyperlink present inside a div tag using Jquery, i used the below codes, which are not helpful.
JQuery - 1.7v
html Code -
<div id="content">TESTING PURPOSE <(a)> href="/test/">Click Here <(a)> End </div>
jQuery - JS
$('#content').find("*").prop("disabled", true);
$('#content').prop("disabled", true);
Upvotes: 2
Views: 12048
Reputation: 1
You can also do this, just give div name of that anchor tag with remove function.
$('.div_name a').remove();
Upvotes: 0
Reputation: 1788
Use preventDefault to disable the default behavior of a link.
Here is a little Code snippet:
$('#content a').click(function(e) {
// stop/prevent default behavior
e.preventDefault();
// do other stuff...
// e.g. alert('Link is deactivated');
});
Here is a little jsFiddle example
Difference between e.preventDefault and return false
Source: Stackoverflow - jquery link tag enable disable
Upvotes: 2
Reputation: 382150
You can do this :
$('#content a').click(function(){ return false });
Returning false
from the click event handler prevents the default behavior (following the link).
If you may have more than one link but you want to disable only this one, you may be more specific in your selector :
$('#content a[href="/test/"]').click(function(){ return false });
Upvotes: 7