I have had a (simple) problem I can't solve for a while. I don't know how to combine myFunction1
and myFunction2
into one function.
<a href="https://www.google.com" id="link1">link1</a>
<a href="https://www.google.com" id="link2">link2</a>
<a href="https://www.google.com" id="link3">link3</a>
function myFunction1(val){
console.log(val);
}
function myFunction2(e){
console.warn('preventDefault');
e.preventDefault();
}
/* this one doesn't work */
function myFunction3(val, e){
console.log(val);
console.warn('preventDefault');
e.preventDefault();
}
document.getElementById('link1').onclick = function(e){
myFunction1('hello');
};
document.getElementById('link2').onclick = function(e){
myFunction2(e);
};
document.getElementById('link3').onclick = function(e){
myFunction3(e, val);
};
So my question is simple, how do you get the third one to work. Work being: passing the val parameter and making the preventDefault
work. So how do you combine myFunction1
and myFunction2
into one function?