1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Disabling the Default Action

Friday May 22, 2009
When you attach an action with JavaScript you don't necessarily want the original action to be performed too.

There are a number of objects on a web page that have their own default action attached that will be performed when your visitors interact with that object (eg. by clicking a link or submitting a form). When you attach Javascript processing to those objects there will be times when you don't want that default action to occur. You can use Javascript to turn off that default action.

Disabling the Default Action
Comments
May 22, 2009 at 3:56 pm
(1) Ted says:

Why did you not make your events unobtrusive?
If you are going to profess that unobtrusive JavaScript is the way to go, then shouldn’t all of your tutorials and articles feature unobtrusive JavaScript? Or is it do as Chappy says, not as Chappy does? Or maybe your just lazy. Or maybe both.

May 22, 2009 at 4:10 pm
(2) Stephen says:

The scripts on this site have been written by me over the past ten years (including those I originally wrote before I started to write here). All of those I have written in the past two years have been completely unobtrusive and I have modified some of the earlier ones to also be less obtrusive than they were when I originally wrote them. If you have a spare five years tucked away in your back pocket then please send it my way so that I can use it to rewrite all the scripts I have ever written to be the way they would be if I wrote them now.

Also there are still other people who haven’t converted all their scripts to be unobtrusive and sometimes they need to make a quick change to fix an error and so articles on how to make such changes are still appropriate.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.