user2104391
user2104391

Reputation: 413

Disabling <a href=""> inside a <div> using jquery

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

Answers (5)

Ashish Kulshreshtha
Ashish Kulshreshtha

Reputation: 1

You can also do this, just give div name of that anchor tag with remove function.

$('.div_name a').remove();

Upvotes: 0

OmShankar
OmShankar

Reputation: 31

$('.modal-body a').css({"pointer-events":"none"});

Upvotes: 0

OmShankar
OmShankar

Reputation: 31

$('#content a').click(function(e) {

  e.preventDefault();

});

Upvotes: 0

Michael J. Zoidl
Michael J. Zoidl

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

Denys S&#233;guret
Denys S&#233;guret

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

Related Questions