Monday, 18 April 2011

JQuery - Dont return false

Dont return false from a jquery method

return false
- This stops everything, including stopping other jquery functions that you may expect to be executed.

Instead you should be using one of:

- this one only stops the immediate default action
- this one stops the event bubbling up

jQuery(document).ready(function ($) {
   $(" h2 a").click(function () {
      var a    = $(this),
          href = a.attr('href'),
          content  = a.parent().next();
      content.load(href + " #content");
      return false; // "cancel" the default behavior

No comments:

Post a Comment