Preventing Default Operation in Javascript

You can stop HTML Elements default operation by using the same addEventListener() method. For Example, you want to add click event to a hyperlink. But, as soon as you click on the hyperlink it follows the link you may or may not specified in href attribute. So, to prevent default operation of this hyperlink we use preventDefault() method.


<a href="" id="homepage">Destructive Labs Alpha</a>


var homepageLink = document.getElementById("homepage");


function ChangeLinkText(e){

homepageLink.text = "DL Alpha";



One thought on “Preventing Default Operation in Javascript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s