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:

event.preventDefault();
- this one only stops the immediate default action
event.stopPropagation();
- this one stops the event bubbling up


jQuery(document).ready(function ($) {
   $("div.post 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