javascript - listening for click event for an href by classname -


there page basic html cannot touch looks this:

<a class="continue-shopping" href="https://someurl">continue shopping</a> 

what want send user different link when click on someurl text link. user can come page containing html many other pages.

i have tried many hours cannot js recognize click event class associated hyperlinked text. use here. js code wrote not work

window.onload = function() { prepeventhandler(); 

}

function prepeventhandler () {  var myclass = document.getelementsbyclassname("continue-shopping");  myclass[0].onclick=window.open(document.referrer,"_self");  /*  make pages go haywire or -- not work */    myclass[0].addeventlistener("click", function() {  window.open(document.referrer,"_self");  }  ) } 

it keeps ignoring second function, , sure doing basic wrong. again, help!

apart preventdefault() use return false

window.onload = function () {     var myclass = document.queryselector(".continue-shopping")         .onclick = function () {         window.location.href = "http://elsewere.com";         return false;     } } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -