Horje
how to not add id to url when click Code Example
how to not add id to url when click
//Get all the hyperlink elements
var links = document.getElementsByTagName("a");

//Browse the previously created array
Array.prototype.forEach.call(links, function(elem, index) {
  //Get the hyperlink target and if it refers to an id go inside condition
  var elemAttr = elem.getAttribute("href");
  if(elemAttr && elemAttr.includes("#")) {
    //Replace the regular action with a scrolling to target on click
    elem.addEventListener("click", function(ev) {
      ev.preventDefault();
      //Scroll to the target element using replace() and regex to find the href's target id
      document.getElementById(elemAttr.replace(/#/g, "")).scrollIntoView({
          behavior: "smooth",
          block: "start",
          inline: "nearest"
          });
    });
  }
});




Javascript

Related
help source code discord.js Code Example help source code discord.js Code Example
remove image Input of element Code Example remove image Input of element Code Example
npm ERR! peer react@"^15.x.x" from react-html-table-to-excel@2.0.0 Code Example npm ERR! peer react@"^15.x.x" from [email protected] Code Example
script src in folder Code Example script src in folder Code Example
Refresh a kendo ui widget, when options on AngularJS $scope change Code Example Refresh a kendo ui widget, when options on AngularJS $scope change Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10