3 ms·
For the example above, you could collapse to: $('.this, .that, .thisotherthing').toggle(); Or if you're looking to throw in a conditional, toggle takes a bool
by labster 8y ago
For the example above, you could collapse to:
$('.this, .that, .thisotherthing').toggle();
Or if you're looking to throw in a conditional, toggle takes a boolean argument:
$('.this').toggle( foo === undefined );
Really it depends so much more on whether or not you're designing a single page app or have some interactive elements on an isolated webpage. Use the correct tool for the correct job.
- benbristow 8y agoActually didn't know toggle took a boolean argument, cheers, I'll probably end up using that. But it's not just that. You've got to account for stuff like updating classes on elements, updating text (e.g you might have a dropdown and when you change that dropdown it updates a summary bar), managing configuration of various components on a page (like options within a select dropdown, available dates in a date picker) etc. etc. All becomes a lot easier using something like React/Vue and they even throw in dev tools to make it easier furthermore.
- DCoder 8y agoThis is the good old imperative-vs-declarative debate. jQuery is "(I think) I know what the current state of the UI is, make these changes", React is "I need the UI to be in this state, you figure out how to get it there". In my experience, with jQuery you spend a lot more time making sure each and every event handler puts all UI elements in a correct state, often repeating yourself or calling the same helper functions. With React, all that computation is concentrated in render(), making it easier to reason about. And if you need to add a new UI element, reviewing all jQuery event handlers will again be a lot more work. Of course, this assumes you are working on a real SPA with a lot of dynamic state, not on a reddit clone where all you need is a reply button to hide/show a textarea and a hidden field to track the parent post id.