Proper way to have an anchor tag with onclick event
Anchor tags are one of the most common HTML tags used in pages. If the user right clicks on the anchor tag he/she will be provided with an option of 'Open in new Window/Open in new Tab'. This will happen only if the anchor has href attribute.
Sometimes it is required to do some other action (like making ajax request) on click of the anchor link and also provide the right click option for the same anchor.
Natural practice by web developers.
<a href="javascript:void(0);" onclick="alert('i am here');">Click Me! </a>
Click Me without link for anchor!
Correct way to add anchor tags without losing anchor properties.
<a href="http://www.blogger.com/amareswar.blogspot.com" onclick="alert('i am here'); return false;">Click Me! </a>
Click Me!
In the above link, you can observe that the user can right click on go to the respective link and onclick will do the custom action provided by the developer.
Sometimes it is required to do some other action (like making ajax request) on click of the anchor link and also provide the right click option for the same anchor.
Natural practice by web developers.
<a href="javascript:void(0);" onclick="alert('i am here');">Click Me! </a>
Click Me without link for anchor!
Correct way to add anchor tags without losing anchor properties.
<a href="http://www.blogger.com/amareswar.blogspot.com" onclick="alert('i am here'); return false;">Click Me! </a>
Click Me!
In the above link, you can observe that the user can right click on go to the respective link and onclick will do the custom action provided by the developer.
Comments
Appreciate your help.
-jana
JavaScript Training in CHennai JavaScript Training in CHennai JQuery Online Training JQuery Online Training
HTML5 CSS3 JavaScript Training in Chennai | HTML5 Online Training
Devops Training courses
Devops Training in Bangalore
Best Devops Training in pune
Microsoft azure training in Bangalore
Power bi training in Chennai
best mobile application company in indore
DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery
Android Training in Anna Nagar
Android Training in Chennai
DevOps course in Tambaram
DevOps Training in Chennai
rest api testing training in chennai
api testing training