dimple
dimple

Reputation: 51

The <a href> link not working on click

This my HTML code

<body>
    <div class=sidebar>       
                <ul class=nav>
                    <li class="home1"><a href="index.php">HOME</a></li>
                    <li class="bye"><a href="bye.php">BYE</a></li> 
                </ul>
     </div>

  <script>

var regex = /1$/
$("ul.nav li").on('click', function(e) {
    var $this = $(this), clickclass = $this.attr("clickclass");

    e.preventDefault();

    if(!regex.test(clickclass)){
        $this.removeClass(clickclass).addClass(clickclass + 1);
        $this.siblings('[class$="1"]').attr('class', function(idx, clickclass){
            return clickclass.substring(0, clickclass.length - 1)
        });
    }
});

</script>

When I click on the link "BYE" it doesn't load the bye.php page it stays on the default home.php... Please help

Upvotes: 0

Views: 3554

Answers (2)

Sonu Sindhu
Sonu Sindhu

Reputation: 1792

remove

e.preventDefault();

it prevent the default event.I hope it will help

Upvotes: 1

Kamil T
Kamil T

Reputation: 2216

The line

e.preventDefault();

prevents all the eventhandlers from invoking, including the redirect.

You can add

window.location.replace($(this).attr("href"));

when your validation succeeds.

Upvotes: 1

Related Questions