How to stop anchor tags from redirecting using Jquery

Hi friends, here is the code to stop anchor tags with class name from redirecting the href link using jquery.


<a href="index.php" class="click">home</a>


<script type="text/javascript">
    $(document).ready(function(){

    $('a').on("click", function(event){
      var clas = $(this).attr('class');
        if (clas == 'click') {
            event.preventDefault();
            // run other statements
        } else {
            //redirect to link
        }
  });
});
    </script>

Description:-

When click on home, it will check the condition where class is equal to click if it is then it stop the anchor tag from redirect, if it is not then it redirect the anchor link.

Comments