0

My ASP.NET WebForms project heavily depends on JQuery. An on some level, I find myself doing the following;

$('#Message').hide();

Then I wondered why I wasn't using plain javascript there as following;

document.getElementById('hideShow').style.display = 'none';

This is just an example and I have other parts of my code which can be easily done with plain JavaScript. (but I have also some of the parts which JQuery takes over)

So my question is that : what is good way of doing this here in regard to performance?

tugberk
  • 57,477
  • 67
  • 243
  • 335
  • possible duplicate of [Is plain vanilla JavaScript better than using frameworks like jQuery or MooTools?](http://stackoverflow.com/questions/3393900/is-plain-vanilla-javascript-better-than-using-frameworks-like-jquery-or-mootools) and a ton of others – BoltClock Jun 25 '11 at 08:29
  • I never use jQuery unless I have jQuery on the page already. It is a balancing act. When you have a lot of validation and suddenly need an accordion or a modal dialog, then switch. If you ALREADY have jQuery, then PLEASE be consistent. Especially since jQuery will rename things like .value – mplungjan Jun 25 '11 at 08:29
  • 4
    @BoltClock: Not a duplicate since here the asker already has jQuery on the page – mplungjan Jun 25 '11 at 08:31
  • @tugberk this is a matter of coding style. That's all. I prefer the JavaScript / DOM approach and use a DOM3 polyfill for my cross browser support. – Raynos Jun 25 '11 at 08:43
  • @Raynos that's another matter but I question was in regard to performance. – tugberk Jun 25 '11 at 08:45
  • 1
    @tugberk oh of course native DOM manipulation is faster. It's a micro optimisation though and we all know micro optimisations are the devil. – Raynos Jun 25 '11 at 08:45

4 Answers4

2
  • jQuery reliefs you from some compatibility issues in browsers.
  • jQuery is very efficient. (Write less, Do more).
  • jQuery has become an industry-standard (very wide use).

For me, I don't like plain Javascript and prefer to use jQuery for the above reasons.

Ken D
  • 5,880
  • 2
  • 36
  • 58
0

One of the key benefits that JQuery provides is browser independence. It handles the quirks between different browser implementations of the core javascript functions.

Ryan Gross
  • 6,423
  • 2
  • 32
  • 44
0

Regarding performance, you have to think that jQuery is an encapsulation of native Javascript code. So, of course native Javascript will execute faster but jQuery has a lot of browsers compatibility problems solved. I can give the exemple of event attach that you declare one way in FF, Chrome, Safari, etc and for IE you have a completely differente syntax.

Another advantage of jQuery is that you write less code to do the same thing, so in the long run your code will be easier to maintain.

João Louros
  • 2,752
  • 4
  • 23
  • 30
  • It will only be easier to maintain if you know jQuery. Raw javascript and dom manipulation is indepedant of framework choice and more maintainable because you dont have to learn popular framework X. – Raynos Jun 25 '11 at 08:47
0

Of course, pure javascript provides better performance. But in the example above, the performance difference is negligible. And I think the code's readability, ease of maintenance and standardization, overcome the minor performance difference.

So jQuery will be my choice.

Oleg Grishko
  • 4,132
  • 2
  • 38
  • 52
  • standardization is questionable. The DOM is standard. Using DOM abstractions means your bound into a library. – Raynos Jun 25 '11 at 08:44
  • @Raynos Right, but probably, you are already using jQuery in your website for more complex scenarios. I think that if you began with jQuery, stick to it across the whole code. – Oleg Grishko Jun 25 '11 at 08:51