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>
  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 +

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:

  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:


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

$('.foobar', this)

...which would be the same as:


Syndicate content