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="" 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.


Unknown said…
Thank you Amareswar Reddy. I was looking for this solution. and you helped me.
Appreciate your help.

navya said…
Wow. This really made my day. Thanks a lot!

JavaScript Training in CHennai HTML5 Training in Chennai HTML5 Training in Chennai JQuery Training in Chennai JQuery Training in Chennai JavaScript Training in Chennai JavaScript Training in Chennai

navya said…
Wow. This really made my day. Thanks a lot!

JavaScript Training in CHennai JavaScript Training in CHennai JQuery Online Training JQuery Online Training
HTML5 CSS3 JavaScript Training in Chennai | HTML5 Online Training
Unknown said…
its good for understanding about html, anchor tag digital marketing company in india
sasitamil said…
After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in

selenium training in Bangalore
selenium training in Marathahalli
selenium training in Btm layout
selenium training in Jaya nagar
selenium training in Electronic city
selenium training in Kalyan nagar
Mounika said…
Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
python Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
anusha said…

Full Stack Development Training in Chennai Searching for Full Stack Development training in chennai ? Bita Academy is the No 1 Training Institute in Chennai. Call for more details.
PoL said…
real estate template WordPress. A responsive website design crafted specifically for real estate. Download it now on TemplateMonster.
Anu said…
I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
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

Popular posts from this blog

CORS issues with IE9 and workarounds

Some thoughts on MongoDB Nodejs driver