1

I have a label with hidden visibility on page load. How can i make it visible using jquery

<label for="error" style="margin:100px auto 60px auto;color:Red; line-height:40px;font-size:medium;visibility:hidden">error occured</label>

I am able to hide it.

  $('label[for="error"]').hide();

This doesn't work

 $('label[for="error"]').show(); 
priya
  • 27
  • 1
  • 1
  • 7

5 Answers5

6

Change your code as follows:

<label for="error" style="margin:100px auto 60px auto;color:Red; line-height:40px;font-size:medium;display:none">error occured</label>

I've replaced your visibility:hidden with display:none.

You can then use the jQuery hide() and show() functions.

Roshna Omer
  • 687
  • 1
  • 11
  • 20
Charlie74
  • 2,883
  • 15
  • 23
4

Set the CSS property visibility to visible.

$('label[for="error"]').css('visibility', 'visible');
vsr
  • 3,138
  • 1
  • 19
  • 14
0

Visibility:hidden and display:none both are the different things:

You can check it's difference Play

You are hiding your element with

visibility:hidden

try display:none instead visibility: hidden

animuson
  • 53,861
  • 28
  • 137
  • 147
Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
0

Your css has "visibility:hidden", which is responsible for hiding the labels, not the jquery method. Use "display:none" instead

twinlakes
  • 9,438
  • 6
  • 31
  • 42
0

Try to use display:none instead of visibility:hidden I've made a jsFiddle for you.

label[for="error"]{
    margin:100px auto 60px auto;
    color:Red; 
    line-height:40px;
    font-size:medium;
    display:none;    
}

http://jsfiddle.net/Pghy3/