I can add a click
event to an HTML element and have the click
event update $(document).data(key,value)
.
This would then trigger $(document).bind('changeData', function() {...}))
. Knowing this, what would be the best way to find out which HTML element updated $(document).data()
?
E.g.:
$(document).bind('changeData', function {
// get the anchor that set $(document).data()
});
$('a').click(function() {
$(document).data('key', 'value');
});
The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea> boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until...
jQuery's setData and changeData events have been deprecated since 1.8 and removed in 1.9. This means that in 2.X and 3.X you're no longer able to bind to these events. Thanks for contributing an answer to Stack Overflow!
The message will display twice, because the handler has been bound to the change event on both of the form elements. As of jQuery 1.4, the change event bubbles in Internet Explorer, behaving consistently with the event in other modern browsers.
The event.data property contains the optional data passed to an event method when the current executing handler is bound. Required. The event parameter comes from the event binding function
Well for the data by click event:
$('#elementSelector').click(function(e){
$(document).data(key, val);
});
$(document).bind('changeData', function(e){
// e.target?
});
If not, try storing the target within the data stored:
$('#elementSelector').click(function(e){
$(document).data(key, {
val: 'value',
target: e.target
});
});
Then when you have the change event:
$(document).bind('changeData', function(e){
var data = $(this).data(key);
var target = data.target;
var value = data.val;
});
https://bugs.jquery.com/ticket/11718
jQuery's setData
and changeData
events have been deprecated since 1.8 and removed in 1.9. This means that in 2.X and 3.X you're no longer able to bind to these events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With