Hacker News new | ask | show | jobs
by FuzzyDunlop 4911 days ago
> Nobody actually does plain “JavaScript” programming for the web anymore, not really anyway. Do they use the core language? Yes. But we no longer use any of the built-in JavaScript->HTML functionality directly.

Which is sort of a shame because there's stuff in there that totally obviates the need to haphazardly traverse the dom with jQuery.

Finding the form an input element belongs to in jQuery:

    $('input').parents('form');

    // or probably
    $('input').parent().parent().parent().find('form');
Finding the same thing using the DOM API:

    document.querySelector('input').form;
You'd want to mix those two, in a real use case:

    $('input').on('click', function(evt) {
        var form = this.form;
    });
Then you don't even need jQuery to use the FormData API:

    // where `submit` uses XHR2 to make a request
    <input type="submit" onclick="submit(this.form)">
1 comments

Unless you want to support IE7, that is. http://caniuse.com/#search=queryselector

Not that I recommend doing so, but in many cases you don't have a choice. Or you started working on a project that originally needed to, and maintaining consistent style might lead you to use jQuery everywhere.

Of course. My main point wasn't the use of querySelector per se, but the ability to access the exact DOM element(s) you need without crazy querying or traversal.

While the DOM API isn't perfect by any means, and jQuery fills that gap really well, there are still times where the OOP nature of the DOM gets you exactly what you want with minimal faff.

The other problem is the relative obscurity of it thanks to jQuery and crowd-sourced DOM documentation (via MDN).

yeah, jQuery certainly eclipses everything else. Though I don't know what you mean by obscurity + MDN... it does seem weirdly anaemic for such a big / complex / important piece of the API, but I don't know if I'd call MDN obscure. Or, I hope it isn't, I find it wildly useful.