I found a snippet of Javascript online... that does exactly what I need to solve a problem. BUT I have not been able to get it to work without errors on Worpress.
The snippet is from here: https://www.the-art-of-web.com/javascript/remove-anchor-links/
<script type="text/javascript">
// Original JavaScript code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
document.querySelectorAll("a").forEach(function(current) {
if(!current.hash) return;
if(current.origin + current.pathname != self.location.href) return;
(function(anchorPoint) {
if(anchorPoint) {
current.addEventListener("click", function(e) {
anchorPoint.scrollIntoView({behavior: "smooth"});
e.preventDefault();
}, false);
}
})(document.querySelector(current.hash));
});
</script>
I have this set up as it's own .js file in the functions.php (and then am enqeueing it via functions.php). It works (perfectly)... but it breaks other functionality.
Any help here would be GREATLY appreciated!
K
question from:
https://stackoverflow.com/questions/65847445/how-to-make-a-basic-snippet-of-javascript-work-in-wordpress 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…