0

I don't want the browser to jump to an given id in :

<a href="documentation-creating-model.php#learningDiagnosis">Learning diagnosis</a>

Few links direct to another page so i need the anchor tag. But in the same page i have written a code to scroll to a proper location.

I have tried:

e.preventDefault();
return false;
e.preventPropogation();

none of the above works.

Basically when on same page i want to override the default scrolling. I have written scrollTop but it doesn't work since the default scrolling take place

Govind Samrow
  • 9,455
  • 13
  • 50
  • 85
Divya Barsode
  • 746
  • 1
  • 5
  • 13

1 Answers1

0

Try to find out # in attr of a tag:

$("a").on("click", function(e) {
    var hasUrl = $(this).attr('href').split('#')[0];
    alert(hasUrl == "")
    if(hasUrl == "") {
      return false;
    } else {
      alert('redirect');
    }
})

Here is updated fiddle

Govind Samrow
  • 9,455
  • 13
  • 50
  • 85