4 ms·
When I see this: var formname = $(this).find('.formname'); formname.empty(); formname.append(n_input); I think why not just use plain Javascript a
by TekMol 8y ago
When I see this:
var formname = $(this).find('.formname');
formname.empty();
formname.append(n_input);
I think why not just use plain Javascript and do this:
document.querySelector('.formname').innerHTML=n_input;
Coders that are attached to libraries and frameworks always seem so afraid to use the tech already available. That they don't even look at how the basic solution would look like.
- Too 8y agoToday yes. Good luck with that back in the Internet Explorer 6 days. Cross browser compatibility is what motivated jquery in the first place, today it has played out its role as a cross browser DOM manipulation library. Modern libraries such as React and Vue however play a totally different role. They introduce proper architecture to web development such as separating the view from your business logic with data binding, they can not be compared with jquery which was just a nicer way of doing the same old manual DOM manipulation.
- deleted 8y ago[deleted]
- chx 8y agoReal life example: https://caniuse.com/#feat=urlsearchparams https://caniuse.com/#feat=urlsearchparams if you need to support IE11 then you can't use the URLSearchParams object. Your best bet is still a jQuery library.
- m90 8y agoSorry for being terribly pedantic, but the "vanilla" version just does not do what the jQuery code does: - `this` might not be document - find might return multiple elements, not just one - if nothing matches, jQuery does not throw unlike the vanilla version I do understand it's just an example, but if you'd consider all the implicit cases the jQuery example covers, you'd end up with a lot more than a single line. I see your point, but using off examples like this don't really sell it too well.
- TekMol 8y agoThese seem to be unintended side effects. From the example it seems the vanilla versions behaviour is what the author wants.
- tracker1 8y agoassuming "this" is an element... `this.querySelector` if you're intending to match multiples... Array.from(document.querySelectorAll(...)).forEach(x => {...}) It's not *that hard... though forEach should be on your dom collection returned, if Array.from exists, but I started shimming Array.from long before either were standard.
- mxschumacher 8y agoI'm currently refactoring a jQuery frontend to native Web. The verbose naming is really unfortunate, jQuery wins here.
- mappu 8y agoApples to apples - $(".formname").html(n_input); The jQuery solution is shorter, and it works in browsers without querySelector (old IE) and without innerHTML (which is missing/readonly for some element types in old IE).