jQuery

Loading the Facebook JavaScript SDK with jQuery

Maybe I'm anal, but pasting the following mess in my page just after loading the jQuery library seems somehow blasphemous.

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: 'your app id', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

Here's how to do it with jQuery:

411 Length Required

Was getting a 411 error response with the message Length Required when making an ajax call from jQuery... the unexpected solution is to pass in an empty data object, like so:

$.ajax({
  url: url,
  type: 'POST',
  data: {},    //  <- set empty data
  success: function(data, textStatus) {
    // do something
  }
});

Source: http://groups.google.com/group/jquery-en/browse_thread/thread/22828981cf23bdc4

Resolved: Logging to Firebug console breaks IE

The firebug console is great for debugging javascript -- but it's really annoying when you want to quickly check something in IE and can't without first removing all your debug statements to avoid a bunch of javascript errors.

Here's a handy log function which checks first that firebug is in use before trying to log to the console. The function is a no-op in IE.

log_debug = function() {
  if(window.console && window.console.firebug) console.log.apply(this, arguments)
}

log_debug('foo', 'bar', 'bash')

Using a context

$('.foobar', context)

...is the same as:

context.find('.foobar')

...but you can also pass in a DOM element:

$('.foobar', this)

...which would be the same as:

$(this).find('.foobar')

Syndicate content