Search code examples
javascriptjqueryhtmlhref

Html | set <a> href url with jQuery


I want to load html in specified situation. For example, signIn button that we can see on the website only load the page (html) if the id and password are correct.

<a class="btn btn-primary btn-lg" id="singIn" href="#" role="button">Sign In</a>

This is the signIn button in html.

$('#singIn').click(function() {
    var userID = $('#userID').val();
    var userPW = $('#userPW').val();
    var tempID = "test";
    var tempPW = "12345";

    if (userID === tempID && userPW === tempPW) {
        alert("userID : " + userID + ", userPW : " + userPW);
      //TODO : load the local html file.
      //var url = $(this).attr("href");
    } else {
        alert("userID : " + userID + ", userPW : " + userPW);
      //TODO : load the other local html file or just alert.
    }
});

This is the part (if/else statement) where I want to load my local html file as I mention first.

How can I do this? Please let me know. Thank you.


Solution

  • Try something like this,

      $(this).attr('href', 'local url goes here');