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

Add method to get element by id #16

Open
losogudok opened this issue Apr 29, 2015 · 3 comments
Open

Add method to get element by id #16

losogudok opened this issue Apr 29, 2015 · 3 comments

Comments

@losogudok
Copy link

Sometimes I need to attach view to a specific element. So, it would be good to have short version of getElementById, like dom.byId(id)

@wraithgar
Copy link
Contributor

Can you use document.querySelector('#myId'), or if you are already in a view view.query('#myId')?

@losogudok
Copy link
Author

document.querySelector I think its too long, thats why we have this module, right?)
Yes, I know about view.query, but I have different situation.

app.extend({
    init: function () {
        var self = this,
            views = {},
            models = {},
            router = new Router(),
            user = new User();

        app.views = views;
        app.models = models;
        app.router = router;
        app.user = user;

        views.main = new MainView({
            el: document.body
        });

        views.content = new ContentView({
            el: dom.byId('content')
        });
        views.appBar = new AppBarView({
            el: dom.byId('appBar'),
            model: user
        });

        window.app = app;
        // Create and fire up the router
        router.history.start();
    }
});

@wraithgar
Copy link
Contributor

Sorry, I was using the native browser api, I'm still not sure we want this personally (would like to hear from other users please). view.query('#foo') works, from what I can tell. Adding a specific byId seems to me like an endorsement of using ids which I think we are trying to not endorse. Ids are a bit of an anitpattern as far as I know. This is (one of the reasons) why we have the data-hook language in the docs.

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

2 participants