I have html pages with links where I want to attach a function to their onclick event. One way to do this, of course:
<a href="save.php" onclick="save(); return false;" rel="save">Save</a>
But I know that this is not the best practice. So instead, I wait for window.onload, scroll through the links and attach the save function to the links with rel = "save". The problem is that it waits until the entire page finishes loading, which may be a few seconds after the link is displayed and clickable.
So is there any other way to do this? Avoid onclick in html, but this makes it work right away when rendering the link.
source
share