I need the same help with migrating from jQuery to vanilla js in ASP.net
jQuery to vanilla
Did anyone came across migrating from jQuery to vanilla js in ASP.net. If so please let me know is there any tool or converter for migration. Any suggestions are welcomed. Please guide me what all needed to work on vanilla js.Is there any plugins or script file that can be downloadable and use it.Also please clarify is vanilla js and JavaScript both are same
2 answers
Sort by: Most helpful
-
-
Bruce (SqlWork.com) 66,706 Reputation points
2022-02-14T17:36:54.61+00:00 yes vanilla js is just javascript and so is jQuery.
jQuery was created during a time when browser dom api's varied a lot (especially IE), and jQuery was a common api to dom. as the browser matured and IE died, there is no a more common robust api. vanilla.js refers to using the new dom api directly rather than a wrapper.
jQuery focused on couple apis:
1) dom node lookup. jQuery supported css selectors for finding nodes. document.querySelector() offers similar functionality
2) dom events. node.addEventListener() offerer similar but limited features. use dispatchEvent instead of trigger
3) css attributes. you can lookup class nodes with query selectors and update the properties directly.
4) add and remove classes from elements. this is now simple with .classList api.
5) create dom elements. the createElement() api is much more standard now.
6) ajax. use fetch insteadthere is no replacement for jQuery's plugin support for building components.
cheatsheet:
https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/
manually converting the code will teach you the dom api and tell you if its worth it.
if you google you will find some tools that will convert snippets of jQuery. but jQuery went beyond the dom api, and there are no replacements for this.
note: in general there is typically not a good reason to port jQuery code to vanilla.js. this is a decision to be made at the start of the project.