Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple onCreate listeners act like duplicates of the first listener #18

Open
chocolateboy opened this issue Oct 1, 2016 · 0 comments

Comments

@chocolateboy
Copy link
Contributor

chocolateboy commented Oct 1, 2016

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" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant