Bug Tracker

Opened 10 years ago

Last modified 10 years ago

#12397 closed feature

Allow passing a function to .data() as an each style setter. — at Version 3

Reported by: gnarf Owned by:
Priority: low Milestone: None
Component: data Version: 1.8.0
Keywords: 1.9-discuss Cc:
Blocked by: Blocking:

Description (last modified by gnarf)

Example Usage:

jQuery( ".button" ).data(function( index, data ) {
    if ( data.href ) {
         // <div class="button" data-href="/">
    }
    if ( data.confirm ) {
         // etc
    }
    jQuery( this ).button();
    // return value discarded, data must remain the same object for other uses
});

The code would be a pretty simple each, and it would let you quickly inspect/alter the data object on an entire jQuery collection.

The same could NOT be done for the elems.data( "key", fn ) signature, because you want to set that key to a function...

Pull Request: https://github.com/jquery/jquery/pull/910

Change History (2)

comment:1 Changed 10 years ago by gnarf

Description: modified (diff)

comment:3 Changed 10 years ago by gnarf

Description: modified (diff)
Note: See TracTickets for help on using tickets.