What are the JQuery bad/worst practices you have seen, written or thing should be avoided?
Nothing is inherently wrong with jQuery, only how you use it. It is a library that makes some JavaScript features easier to use, and it can save time and headaches in lots of projects. The problem is that anything that's easy to use is misused by beginners.
Yes, they're both JavaScript, you can use whichever functions are appropriate for the situation. Show activity on this post. That kind of lower-level hacking around the DOM, messing with the inline handlers, and cross-browser quirks thereof, is precisely the reason jQuery was born.
It's a bad practice because React uses a concept called a Virtual DOM instead of a real DOM. And React isn't aware of the changes made outside of this Virtual DOM. When you use jQuery or any other library that manipulates the DOM, React gets confused.
A thing you should avoid is using the "easy to use" selectors in every line once again, because the JavaScript implementation of selectors is not that efficient. Of course, the jQUery guys are optimizing it, however I think you should use it as little as possible.
So, this is a bad practice.
$("li ul span").show();
$("li ul span").toggleClass("bubu");
Chaining is good
$("li ul span").show().toggleClass("bubu");
And remembering things in a local variable is also not bad:
var allspans = $("li ul span");
allspans.show();
allspans.toggleClass("bubu");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With