Reputation: 58454
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?
Upvotes: 0
Views: 335
Reputation: 4281
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.
Upvotes: 0
Reputation: 2760
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.
Upvotes: 0
Reputation: 5968
For me, I don't like plain Javascript and prefer to use jQuery for the above reasons.
Upvotes: 2
Reputation: 6515
One of the key benefits that JQuery provides is browser independence. It handles the quirks between different browser implementations of the core javascript functions.
Upvotes: 0