Comments on: Things you may not know about jQuery https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Antony Kennedy https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-701 Thu, 19 Nov 2009 11:11:48 +0000 https://j11y.io/?p=558#comment-701 @Mark Schultheiss

Yes, ready is an event handler (a great one, since it fires when the DOM is ready, rather than waiting for images to load).

However, when using it, you want to pass a reference to the function, not execute the function itself.

Rather than:

jQuery(document).ready(MyFunction());

Do:

jQuery(document).ready(MyFunction);

Also, one of the nicest things jQuery does, is if you pass it a function straight away, that is a shortcut to the document ready event.

jQuery(document).ready(MyFunction);

Is exactly the same as:

jQuery(MyFunction);
]]>
By: Mark Schultheiss https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-700 Fri, 30 Oct 2009 15:17:14 +0000 https://j11y.io/?p=558#comment-700 Lots of peeps do not actually realize jQuery(document).ready(); is really and EVENT HANDLER! – handle the .ready() event.

Call a function on page load:
function MyFunction()
{
// do lots of my stuff here
}
jQuery(document).ready(MyFunction());

OR
jQuery(document).ready(function(){// do little stuff here});

]]>
By: Ron https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-699 Wed, 01 Jul 2009 02:27:55 +0000 https://j11y.io/?p=558#comment-699 Great list! There was at least one I needed! 😀 Thanks!

]]>
By: Jibbidy https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-698 Tue, 05 May 2009 18:38:38 +0000 https://j11y.io/?p=558#comment-698 I was a little confused by the namespacing events example:

jQuery.fn.myPlugin = function() {
 
    // Clean up after yourself!
 
    jQuery.myPlugin = {
        cleanUp: function() {
 
            // Remove all click handlers binded
            // as a result of the plugin:
            jQuery('*').unbind('click.myPlugin');
 
            // ALternatively, remove ALL events:
            jQuery('*').unbind('.myPlugin');
 
        }
    };
 
    return this.bind('click.myPlugin', function() {
        // Do something...
    });
};
 
// Note, you can also namespace data:
// E.g. $(elem).data('whatever.myPlugin',value);

1. Why put the cleanUp function inside jQuery.myPlugin = {…}, couldn’t you just use var cleanUp = function() {…} ?

2. If you needed to declare some variables for you plugin’s state, where would you put them: in the jQuery.fn.myPlugin = function() {…} block; or the jQuery.myPlugin = {…} block?

My apologies if these are stupid questions. 🙂

]]>
By: Mark Hoffman https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-697 Sat, 02 May 2009 18:18:01 +0000 https://j11y.io/?p=558#comment-697 Great post! Found the answers to several JQuery questions that I had. Thanks for taking the time to post this!

]]>
By: olivvv https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-696 Sun, 12 Apr 2009 21:12:55 +0000 https://j11y.io/?p=558#comment-696 nice stuff.

I think there is a little type here, the second ‘i’ should be replaced by a ‘j’

// List bound events:
console.dir( jQuery('#elem').data('events') );
 
// Log ALL handlers for ALL events:
jQuery.each($('#elem').data('events'), function(i, event){
    jQuery.each(event, function(i, handler){
        console.log( handler.toString() );
    });
});
 
// You can see the actual functions which will occur
// on certain events; great for debugging!
]]>
By: cancel bubble https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-695 Wed, 25 Mar 2009 21:00:22 +0000 https://j11y.io/?p=558#comment-695 jQuery’s Event object has “keyCode” for keyup/keydown events and “which” for keypress and mouse events (which button was pressed). I think “which” is reliable cross browser, it gives you the character code of keypress events.

]]>
By: Ferdy https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-694 Wed, 11 Mar 2009 18:24:08 +0000 https://j11y.io/?p=558#comment-694 Great post, thank you for the effort.

One minor remark: you say the the event object is normalized across all browsers. This is true, but I do like to point out that the event triggers are not normalized. For example, listening to keypresses works differently in different browsers, the same goes for the submit event, which is different in Opera.

]]>
By: Renzo https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-693 Wed, 11 Mar 2009 03:24:37 +0000 https://j11y.io/?p=558#comment-693 JQuery is way ahead of prototype and mootools. JavaScript can be really tricky, and I find this article really helpful.

]]>
By: Jeffrey Jose https://j11y.io/cool-stuff/things-you-may-not-know-about-jquery/#comment-692 Sat, 21 Feb 2009 21:38:32 +0000 https://j11y.io/?p=558#comment-692 Another nice tutorial from James. Really appreciate the amount of thought and work behind this. really shows. Extremely useful.

Keep ‘hem coming and Congrats !

]]>