Use <a href> link and <onclick> function together

How to make this a tag working with href and onClick function?
(The onClick should run first then href)

Version 1
`` <a href="#" id="myHref">Click me</a>

$("#myHref").on('click', function() {
    document.getElementById(".myDiv").style.flexGrow = "5";
     window.location = "http://www.google.com";

});`

Version 2

 <a href="http://www.google.com" onclick="return myFunction();">Link</a>


function myFunction() {
    document.getElementById(".myDiv").style.flexGrow = "5"; 
}
$("#myHref").on('click', function(event) {
    event.preventDefault();
    document.getElementById(".myDiv").style.flexGrow = "5";
    window.location = "http://www.google.com";
});

But you won’t see the effect when you’re immediately redirecting anyway.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.