Jquery selection methods

I like to use the hide () and show () methods, but I came across the fact that they never use it. Instead, I see that they use attr () for everything related to the mapping.

$("#element").attr("style", "visibility:hidden");
$("#element").attr("style", "visibility:visible");

Is it just purely preferential? Or is it more profitable to use one against the other?

+3
source share
3 answers

There is a difference. Take for example: .hide()

This is roughly equivalent to calling .css('display', 'none'), (...)

visibilityand are two different CSS properties. Usage leaves room for the item in the layout, but does not display it. displayvisibility: hidden;

() , .attr("style", '...') , .

+3

() () HTML.

, ; , , .

+1

. show() hide() , , . , hide (, ..). http://api.jquery.com/hide/

.css('display', 'none') .css('display', 'block'), , , .

show()/hide() .css() , , .

One more note. TheDramaLama said hide () removes the item from the source code. I think TheDramaLama means that it deletes it in its own way, but it still remains in the source code (aka DOM).

+1
source

All Articles