---
title: "return false considered harmful in live"
description:
  "If you return false in live operation of jQuery a few unexpected things can
  happen. See this blog for details."
canonical_url: "https://www.bigbinary.com/blog/return-false-considered-harmful-in-live-jquery"
markdown_url: "https://www.bigbinary.com/blog/return-false-considered-harmful-in-live-jquery.md"
---

# return false considered harmful in live

If you return false in live operation of jQuery a few unexpected things can
happen. See this blog for details.

- Author: Neeraj Singh
- Published: March 10, 2010
- Categories: jQuery

Checkout following jQuery code written with jQuery.1.4.2. What do you think will
happen when first link is clicked.

```javascript
$("a:first").live("click", function () {
  log("clicked once");
  return false;
});
$("a:first").live("click", function () {
  log("clicked twice");
  return false;
});
```

I was expecting that I would see both the messages. However jQuery only invokes
the very first message.

`return false` does two things. It stops the default behavior which is go and
fetch the link mentioned in the `href` of the anchor tags. Also it stops the
event from bubbling up. Since live method relies on event bubbling, it makes
sense that second message does not appear.

Fix is simple. Just block the default action but let the event bubble up.

```javascript
$("a:first").live("click", function (e) {
  log("clicked once");
  e.preventDefault();
});
$("a:first").live("click", function (e) {
  log("clicked twice");
  e.preventDefault();
});
```

## Links

- [Human page](https://www.bigbinary.com/blog/return-false-considered-harmful-in-live-jquery)
