开发者

Is using JQuery a good idea when the thing can be done with plain JavaScript easily

My ASP.NET WebForms project heavily depends on JQuery. An on some level, I find myself doing the follo开发者_运维知识库wing;

$('#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?


  • 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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜