Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does setting jQuery.data() trigger an event?

I'm wondering if calls to $(".domElement").data("key", "newValue") will trigger an event that I can handle? I've tried binding change but this doesn't get triggered when data is set.

I think this question may be asking something similar, but binding changeData didn't work either - jQuery data() and 'changeData' event.

like image 605
Matt Avatar asked Dec 06 '22 06:12

Matt


1 Answers

Actually you have only tried to attach the custom event but you will also have to trigger it something like:

$('button').click(function (e) {
    $('#someID').data("key", "newValue").trigger('changeData'); 
});

$('#someID').on('changeData', function (e) {    
    alert('My Custom Event - Change Data Called! for ' + this.id);
});

FIDDLE DEMO

like image 133
palaѕн Avatar answered Dec 08 '22 20:12

palaѕн