I've been trying to create a button that will redirect to a new link when clicked, but I've tried multiple options and can't seem to get it to work.
var button = document.createElement("button");
button.innerHTML = "$1.00";
divInnerElement.appendChild(button);
button.addEventListener ("click", function() {
window.location('http://www.google.com','_blank');
return false;
});
Update: The function works, but it only reloads the current page instead of redirecting to a different page. Using window.open works, but I don't want a new window to open.
Update:
I'm not sure what was causing the issue with window.location, but adding an aTag inside the button fixed the problem.
<script>
var button = document.createElement("button");
var aTag = document.createElement('a');
aTag.setAttribute('href','http://www.google.com');
aTag.innerHTML = '$1.00';
button.appendChild(aTag);
divInnerElement.appendChild(button);
// button.addEventListener ("click", function() {
// window.location.href = 'http://www.google.com';
// return false;
// });
</script>