Asim Zaidi
Asim Zaidi

Reputation: 28324

jquery's .css('visibility', 'hidden') method isn't hiding the element

I have the following code

$(function() {

  $('#totalRecords').css('visibility', 'hidden'); 
  alert("hi");

 });

Problem is that it doesnt hide my drop down which is

   <span id="lblCodes" class="pol" style="top:4;left:209;">Codes</span>
  <span id="totalRecords" class="pol" style="top:4;left:350;visibility:visible;">
  <select id="startRecord" >
   <option value="0"></option>
  </select>
  </span>  

Is there a method for parent() or something. I thought jquery would just select from id. I see alert("hi") prompt but the dropdown doesnt get hidden

thanks

Upvotes: 0

Views: 180

Answers (4)

Pipalayan Nayak
Pipalayan Nayak

Reputation: 957

I think you are choosing the wrong id for the selector. If you need to hide the dropdown, use $('#startRecord').hide(); OR $('#startRecord').css('display', 'none'); OR $('#startRecord').css('visibility', 'hidden');

Note: visibility and display are different in their functionality.

Upvotes: 0

ajay_whiz
ajay_whiz

Reputation: 17941

remove "visibility:visible" from style attribute and use $('#startRecord').hide();

Upvotes: 1

Ted Gueniche
Ted Gueniche

Reputation: 813

I would say you should use the "display" attribute and set it to "none" to hide an element. So your code would be:

$('#totalRecord').css('display', 'none'); 

And it should be "totalRecord" instead of "totalRecords"

Upvotes: 1

Russ Cam
Russ Cam

Reputation: 125528

did you not mean

  $('#startRecord').hide(); 

You seem to have the wrong id in your selector for the dropdown. Also, visibility and display are quite different. Unless you want the hidden dropdown to still occupy the space, you'll want to use display instead of visibility

Upvotes: 4

Related Questions