question

AlisaBonjour-5391 avatar image
1 Vote"
AlisaBonjour-5391 asked Bruce-SqlWork edited

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


dotnet-aspnet-core-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GeorgeAJohnson-6254 avatar image
0 Votes"
GeorgeAJohnson-6254 answered GeorgeAJohnson-6254 published

I need the same help with migrating from jQuery to vanilla js in ASP.net


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork edited

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 instead

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.