Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visibility attribute question

Tags:

html

jquery

css

What is the difference between

$("#myid").attr("style", "visibility: hidden")

and

$("#myid").css("visibility", "hidden")

?

like image 912
Misha Moroshko Avatar asked Apr 22 '10 12:04

Misha Moroshko


2 Answers

Doing this:

$("#myid").attr("style", "visibility: hidden") 

Will leave only this style attribute, while doing this:

$("#myid").css("visibility", "hidden") 

Will add (or set) this style attribute.

Here's an example, the first will always result in this:

style="visibility: hidden;" 

The second just adds visibility so your style may now be:

style="width: 50px; color: red; visibility: hidden;" 
like image 123
Nick Craver Avatar answered Sep 21 '22 00:09

Nick Craver


Nothing. Just two ways to accomplish the same goal.

The first will overwrite any existing style settings. If you had:

<div style="font-weight: bold;" /> 

It would become:

<div sytle="visibility: hidden;" /> 

The second will add the visibility setting to the existing styles. So:

<div style="font-weight: bold;" /> 

Woudl become:

<div style="font-weight: bold; visibility: hidden;" /> 

If there's no style attribute already set, then the two will produce the same end result.

like image 27
Justin Niessner Avatar answered Sep 19 '22 00:09

Justin Niessner