jQuery-onMutate
jQuery-onMutate copied to clipboard
Multiple onCreate listeners act like duplicates of the first listener
Raising this as a new issue as #16 and #17 have both been closed.
jQuery-onMutate: 1.4.2 Browser: Firefox 49.0.1 jQuery: 3.1.1 OS: Linux (Arch)
I'm still seeing this with 1.4.2.
JSFiddle
https://jsfiddle.net/g7L7apj2/10/
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdn.rawgit.com/eclecto/jQuery-onMutate/v1.4.2/src/jquery.onmutate.min.js"></script>
<style>
label, textarea { display: block }
</style>
</head>
<body>
<label for="output">Output:</label>
<textarea id="output"></textarea>
<script>
var seen = [];
function update () {
$('#output').val(JSON.stringify(seen));
}
function created ($el) {
seen.push($el.attr('id'));
update();
}
$.onCreate('#foo', created);
$.onCreate('#bar', created);
update();
setTimeout(function () {
$('body').append('<div id="foo">Foo</div>');
}, 1000);
setTimeout(function () {
$('body').append('<div id="bar">Bar</div>');
}, 2000);
</script>
</body>
</html>
Expected Output
[ "foo", "bar" ]
Actual Output
[ "foo", "foo" ]