JQuery show () and hide () vs classes with display: block / none

Just out of curiosity, which of these two methods is more "valid" to use?

I had a discussion with my supervisor and he told me that I should create two classes with a display: block / none and assign them to elements using jQuery, instead of using the jQuery show / hide native functions.

I got the impression that show / hide are commonly used functions that work without any problems, and they were made to make our life easier, without forcing us to assign classes.

+4
source share
4 answers

CSS, , jQuery.show(). jQuery.show() , CSS, , . , , . , show/hide .

$username.hide();

$username.addClass('hidden');

, , , ... ..

+1

- show() hide() display: block ( inline, inline-block ..) display: none . "".

, show() hide() jQuery . , CSS, show() hide() do (inline html, display). .

show() hide() display, , hide() , show(), , display ( , display).

0

"" . , . jQuery show/hide .

  • show/hide, javascript/jquery.
  • CSS, jquery, CSS + jquery

, CSS, . /, , . , , , ypur.

0
source

I think the difference in approaches is that by doing this with classes, you can choose how to hide in future repeat styles. You might want to swap the new CSS one day when the hidden text really intersects and turns gray. Using classes, you maintain separation of view and data.

0
source

All Articles