2

Might be a silly question, but I am confused between .queue() used with .dequeue() and $.queue() OR jquery.queue().

Are they the same, if so why jquery provided them in 2 separate documentations? Can, someone explain their ussage differences along with appropriate examples ?

https://api.jquery.com/queue/

http://api.jquery.com/jquery.queue/

2
  • 3
    the first one is applied to a jquery object, it means for all "selected" elements, while the second one to one element only Commented Apr 23, 2015 at 7:26
  • That helped. Thnx pavel. Commented Apr 23, 2015 at 9:26

2 Answers 2

3

.queue() is used as a method of the jQuery element.

It has only one parameter "queueName"

$("div:first").queue("fx")

Whereas jquery.queue() is a standalone function that will accept DOM element as it's first parameter and second for name of the queue.

jQuery.queue($("div:first")[0], "fx" );

Both works same, just the approach is different.

Sign up to request clarification or add additional context in comments.

4 Comments

This means, we dont need to use '$.queue()' or '$.dequeue()' separately, as we can do all that work with help of ".queue()" and ".dequeue()" eazily ?
Yes, we don't need to do. jQuery team has documented both Lower level and Higher level methods.
Is there any other function for which jQuery Team has documented both "Lower" & "Higher" Level methods apart from .queue() & .dequeue() ?
Yes, another example is .data() (api.jquery.com/data) and jQuery.data() (api.jquery.com/jquery.data)
1

As said at http://api.jquery.com/jquery.queue/

Note: This is a low-level method, you should probably use .queue() instead.

Internally $(selector).queue() and $(selector).dequeue() use $.queue() and $.dequeue() respectively.

This is the code for $(selector).queue() and $(selector).dequeue() jQuery 2.1.3:

jQuery.fn.extend({
    queue: function( type, data ) {
        var setter = 2;

        if ( typeof type !== "string" ) {
            data = type;
            type = "fx";
            setter--;
        }

        if ( arguments.length < setter ) {
            return jQuery.queue( this[0], type );
        }

        return data === undefined ?
            this :
            this.each(function() {
                var queue = jQuery.queue( this, type, data ); // <-- HERE!

                // Ensure a hooks for this queue
                jQuery._queueHooks( this, type );

                if ( type === "fx" && queue[0] !== "inprogress" ) {
                    jQuery.dequeue( this, type ); // <-- HERE!
                }
            });
    },
    dequeue: function( type ) {
        return this.each(function() {
            jQuery.dequeue( this, type ); // <-- HERE!
        });
    },

....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.