8 ms·
Fast and lightweight, yes. But vanilla-js is certainly not cross platform ;) You see, that's actually one of the biggest problems with JS and one of the main re
by ashray 14y ago
Fast and lightweight, yes. But vanilla-js is certainly not cross platform ;) You see, that's actually one of the biggest problems with JS and one of the main reasons why people use things like jQuery (apart from the pretty API..).
That cross platform bit is the weakest link sigh.
- dotborg 14y agojQuery API is not pretty
- freepipi 14y agoI am a c developer, now I want to learn jQuery , but its syntax seems so weird to me, Vanilla JS looks more comfortable to me , one questions, does it supported by webkit?
- pooriaazimi 14y agoI'm sorry. I don't know if you're joking or are serious. But if you're a C programmer and have no experience with JS I guess it must be really easy to be fooled by this "joke". Some JS people (the ones usually with a long beard) hate how kids use frameworks like jQuery and this site is an attempt at telling them "The vanilla JS, i.e. the standard language that all browsers use and your cool jQuery leverage under the hood, is quite capable these days. Use it". They are not quite right, but aren't quite wrong either (IMO). You'll be a dreadful JS programmer if you only know jQuery. JS is sooo different from C (and Java) that if you don't know the core language everything you'll do will be wrong. For starter: there's no block scope. Only function scope. Every JS programmer should read "JavaScript: The Good Parts" by Douglas Crockford cover to cover - before learning jQuery.
- ams6110 14y agothere's no block scope. Only function scope. There is global scope as well, and it's (unfortunately in most cases) the default.
- MatthewPhillips 14y agoAlso there is block scope. let { ... }
- evilduck 14y agoAFAIK, let is a Mozilla only feature.
- freepipi 14y agoI want to learn something about jQuery,because recently I need to develop an application which use webkit. It has a feature that need to highlight some special words. After search in the internet, I found the jQuery can 'easily' do that. But the syntax of jQuery make me headache, then I happened to see this article. Thank you very much , I am very appreciate for your advice:)
- emehrkay 14y agoLook at other libraries. I cant beat the MooTools drum loud enough.
- dag11 14y agoI'll take $('p').text('Hello.') over for (var p in document.getElementsByTagName('p')) { p.innerHTML = 'Hello.'; } any day!
- aaronblohowiak 14y agoinnerHTML is an easy one, try setting an attribute -- you have to create a new attribute node, set its value and then add that to the element..
- mibbitier 14y agosetAttribute()?
- aaronblohowiak 14y agoIE8 =(
- masklinn 14y ago> you have to create a new attribute node, set its value and then add that to the element.. Erm... no you don't: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-F68F082 http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-F68F082
- aaronblohowiak 14y agoIE8 =(
- gildas 14y agoYou should set the node property instead (e.g. standard textContent or innerText). It will work everywhere.
- dotborg 14y agodid you ever try to debug your pretty jquery karate? ps. second example is not valid, in Vanilla JS you do it like this: document.getElementsByTagName('p').filter(function(el) { el.innerHTML = 'Hello.'; });
- aaronblohowiak 14y agoCompared to the dom api, it is very pretty.
- deleted 14y ago[deleted]
- mw642 14y agoIf you're only targeting modern browsers (latest Chrome/FF/Opera/Safari, IE10), is this still true? I was under the impression the recent browsers were standards-compliant enough that you could use vanilla JS. Of course, most developers still have to target older browsers, but for a private Web app where you know your target audience, this shouldn't be a huge issue.
- MatthewPhillips 14y agoThere are always quirks, which I assume is what the grandparent is referring to. For example, in WebKit popstate happens on page load, in Firefox it does not. There are many such quirks. Still not worth using a DOM library that will hurt performance, though, in my opinion.
- drivebyacct2 14y agoAnd what's IE10s market percentage? Less than a fraction of a fraction of a percent I bet. And with current reviews of Win8, I don't see that changing in a meaningful way for soooome time.
- melling 14y agoI think you missed the announcement where Microsoft is going to do a silent update of IE10 to consumer PC's. IE9 usage will drop to the low single digits within a year and IE10 will take its place as the leading IE browser.
- scarmig 14y agoAren't the polyfills pretty good nowadays?
- TazeTSchnitzel 14y agoYes, but using all of them needed for full HTML5 support in, say, IE6, probably takes up more bandwidth than downloading a new browser.
- taligent 14y agoMost people using IE6 are doing so because they can't download a new browser e.g. ActiveX support or lockdown corporate machine.
- gobengo 14y agoIt doesn't take up any more bandwidth if you're properly concatenating your JS.
- TazeTSchnitzel 14y agoUh, no. I think you misunderstand me.
- gobengo 14y agoYou're right. That was fairly nonsenical. Not sure what I meant, perhaps I read your comment as referring to requests. Either way, long-term caching of such shims means the bandwidth to load polyfills only has to be expended once per client. And an extra Mb of bandwidth once per year is a pretty reasonable thing to do for particularly older browsers if it makes your development more sane.