Easy way to prevent default action when using "onclick" of a checkbox?

javascript, jquery, web-applications

Solution

The return value of an event handler determines whether or not the default browser behaviour should take place as well.

So ...

onclick='function(); return false;' 

should fix it ...

Problem

This is my current solution: html ``` <input type="checkbox" value="1" onclick="return do_stuff();" /> <input type="checkbox" value="1" onclick="return do_stuff2();" /> ``` javscript: ``` function do_stuff() { return false; } function do_stuff2() { return true; } ``` http://jsfiddle.net/NXKMH/12/ I would like to avoid needing the "return" in the onclick call (ex. `onclick="do_this();"` instead of `onclick="return do_this();"`). I thought about using the preventDefault() function that jquery provides, but cant seem to get that working. Also, I dont want to bind "click" event if possible. I prefer using the "onclick". (easier to work with ajax loaded content) Thoughts?

Original source

Related problems