• Publisert
  • 1 min

Bringing jQuery 3's show, hide and toggle into the future

The show and hide methods in jQuery have always been a convoluted mess, performing poorly and not on board with responsive design. How about an HTML5-based solution?

In July 2015, the jQuery team published the alpha for version 3.0 of the ubiquitous JavaScript library. The blog post describing changes for the new version contained a "here be dragons" warning about the overused and misused show, hide and toggle methods:

We know that this is likely to be one of the most contentious and difficult changes in jQuery 3.0, so we wanted to put it out in this early release to see the effects. 

The change? These methods would no longer do complicated checks to set/reset the display style on an element that had been altered via the show, hide or toggle methods.

They proposed a simpler model: show() would remove "display: none" from the inline style of the element, hide() would set it. That's it.