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
- you should use
preventdefaultmake sure browser not run defaulthref. - 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
Post a Comment