Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementById("remember").visibility = "hidden"; not working on a checkbox

I cannot get the visibility or display properties to work.

Here is the HTML footer:

<div id="footer">
  &copy; 
  <strong id="foot" onmouseover="showData();" onmouseout = "hideData()">
    Exquisite Taste 2012
  </strong>
  <input type='checkbox' id="remember" onclick='editCookie()' style="visibility:hidden;" />
</div>

Here is the .js function with the visibility part not working:

function showData()
{


  document.getElementById("remember").visiblity="visible";


  document.getElementById("foot").innerHTML = getDate() + "  " + getTime();

  if(cookieValue())
  {
    document.getElementById("remember").checked = true;
  }
}

That one line doesn't seem to do anything:

document.getElementById("remember").visiblity="visible";
like image 473
Ben Avatar asked Dec 23 '12 00:12

Ben


People also ask

What is the difference between display none and visibility hidden?

display:none means that the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags. visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page.

What does getElementById return if not found?

The getElementById() method returns null if the element does not exist.

What is the difference between display and visibility in CSS?

CSS Display − none does not render the element on the document and thus not allocating it any space. CSS Visibility − hidden does renders the element on the document and even the space is allocated but it is not made visible to the user.

How do I set visibility visible in jQuery?

visible = function() { return this. each(function() { $(this). css("visibility", "visible"); }); }; }(jQuery));


2 Answers

There are two problems in your code:

  • The property is called visibility and not visiblity.
  • It is not a property of the element itself but of its .style property.

It's easy to fix. Simple replace this:

document.getElementById("remember").visiblity

with this:

document.getElementById("remember").style.visibility
like image 54
ThiefMaster Avatar answered Oct 05 '22 23:10

ThiefMaster


This is the job for style property:

document.getElementById("remember").style.visibility = "visible";
like image 32
VisioN Avatar answered Oct 05 '22 23:10

VisioN