I am using ajax to redirect pages without refreshing for a tags. However, it randomly works. Sometimes, it doesnt even generate log that I put inside the function on purpose to check if its called. I guess a tag performs href that is already declared on inline. How do I make this 100% work?
$(".view-about-us a").on('click', event=>{
event.preventDefault();
var new_url = $(this).attr("href");
$.ajax({
    dataType: 'html',
    type: "POST",
    url: new_url,
    data: {
    },
    success: function(result) {
      window.history.pushState(null, null, new_url);
      var htmlString = result;
      var parser = new DOMParser();
      var doc = parser.parseFromString(htmlString, "text/html");
      var parent = doc.querySelector(".main-container");
      var children = parent.childNodes;
      children.forEach(child => console.log(child));
      $(".main-container").html(children);
    },
    error: function(result) {
        alert('error');
    }
});
});
 
    