All posts tagged jQuery

$( this ).attr( … ) Is Often Unnecessary

by Ian Dunn

It’s often much more efficient to access DOM properties directly , rather than using jQuery. The downside to that approach is that there are differences between the various browsers, so in some cases it introduces bigger problems than the extra performance overhead.

Registering jQuery Event Handlers Before the Elements Exist

by Ian Dunn

Dave Ward wrote an article  Don’t let jQuery’s $(document).ready() slow you down that shows a few situations where execute the contents of a JavaScript file immediately, rather than wrapping it all inside jQuery( document ).ready(). The .live() method has been deprecated since he wrote the article, though; .on() is its replacement.

Faster jQuery Selector Calls with Chaining

by Ian Dunn

Rob Tarr ran some benchmarks to prove the claim that chaining jQuery selector methods is faster than placing them all in a single method call.

Passing Extra Arguments to a jQuery Event Handler

by Ian Dunn

This Fiddle shows how to pass extra parameters to an event handler function in jQuery.

admin-ajax.php Response Fails When Called from Domain Alias

by Ian Dunn

I’m writing a WordPress plugin that uses AJAX and I had everything setup and working fine for awhile. I came back to the code a few hours later and all of the sudden I was getting a failed response, even though the code hadn’t changed. I got the correct JSON response when I loaded the… [more]

jQuery document.ready() Fires Twice

by Ian Dunn

There’s a bug in jQuery 1.4.3 that causes document.ready() to fire twice if there’s an unhanded exception. You can avoid it by wrapping the code that is throwing the exception inside a try/catch block.

IE Pixelates Text During Javascript Animations

by Ian Dunn

If you’re performing a JavaScript animation effect on an element (e.g., jQuery’s fadeIn/fadeOut), you may notice that the text briefly pixelates in IE . You can fix that by setting a background color on the element.

Cross-Domain AJAX Requests

by Ian Dunn

Browsers prevent standard AJAX calls across domains for security reasons, but you can make JSONP calls instead. If you’re using jQuery you just need to add ‘callback=?’ to the url: Then setup the request handler to prepend the callback parameter to the response and wrap it in quotes: If you’re using Firebug to monitor the… [more]

Alternatives to Select/Multiple

by Ian Dunn

Ryan Cramer details some of the problems with select/multiple and a few good alternatives . It’s useful in certain circumstances, but unintuitive and error-prone. Instead, you can create a list of checkboxes inside an element with overflow:auto set, or use a jQuery plugin he developed.

Add this ribbon to your WordPress website re-abolish slavery