0

Im just ask my question fast.(because my english is not so good)
Can i use delegate like this or other similar way?

$( 'body ').delegate({
    'input[type=text]': {
        'change': function( e ) {
            //codes..
        },
        'blur': function( e ) {
            //codes..
        }
    },
    '.ipsum': {
        'click': function( e ) {
            //codes..
        }
    }
});
traBolics
  • 89
  • 1
  • 3
  • 13

1 Answers1

0

Which version of jQuery are you using? If you are using jQuery 1.7 or above then use .on() instead .delegate().

More information about this can be found at .delegate() vs .on()

To go back at your example:

The best way would be to split the 2 elements like this:

$('input[type=text]').on({
    change: function() {
        // code
    },
    blur: function() {
        // code
    }
});

Second element:

$('.ipsum').on({
    click: function() {
        // code
    }
});
Community
  • 1
  • 1
Mivaweb
  • 5,580
  • 3
  • 27
  • 53
  • Im using 1.11.1 and i know the on() function. on() not work like delegate(). I perferred to use delegate() but i connot do it my way :/ – traBolics Dec 11 '14 at 10:44
  • what is the reason you want to combine the elements and events in one delegate? – Mivaweb Dec 11 '14 at 10:45
  • Tell me, which one is better. Using delegate for 5 elements(has 2 or 3 event) separately or using 1 delegate for 5 elements? .. For example > delegate for .one, delegate for .two, delegate for .three, delegate for .four, delegate for .five ||or|| delegate for (.one,.two,.three,.four,.five) wich one is better logic? – traBolics Dec 12 '14 at 01:11
  • do they have the same logic for each of these elements? – Mivaweb Dec 12 '14 at 07:04