javascript - Disable href and execute function -


i have code:

<a href="link.cshtml">     <div>...</div>     <div class="function">...</div>     <div>....</div> </a> 

i disable href on div class function , call function when click on div.

i have tried onclick="return false; testfunction();" doesn't work.

can me?

thanks in advance

  1. you should use preventdefault make sure browser not run default href.
  2. if return - nothing run after that...

function testfunction() {    alert('hi');  }  document.queryselector('.function').addeventlistener('click', function() {    event.preventdefault();    testfunction();  });
<a href="https://www.yahoo.com">      <div>...</div>      <div class="function">click here not change page</div>      <div>....</div>  </a>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -