Skip to content

Instantly share code, notes, and snippets.

@bobbrez
Created March 28, 2012 17:20
Show Gist options
  • Save bobbrez/2228387 to your computer and use it in GitHub Desktop.
Save bobbrez/2228387 to your computer and use it in GitHub Desktop.
Javascript Question

So you have a document like this:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <textarea id="myText"></textarea>
  </body>
</html>

In your Chrome console, you've done var view = document.getElementById('myText');

Now...

When you do view.setAttribute("hidden", true); the document now looks like:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <textarea id="myText" hidden=true></textarea>
  </body>
</html>

This will hide the element because there is a property hidden that exists. Because hidden is a property in HTML, its existence is all that is needed, the value is ignored.

When you do view.setAttribute("hidden", false); the document now looks like:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <textarea id="myText" hidden=false></textarea>
  </body>
</html>

But because hidden is a property, the value is ignored and its presence is what sets it hidden.

When you do view.hidden=false; the document now looks like:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <textarea id="myText"></textarea>
  </body>
</html>

view.hidden=false is equivalent to view.removeAttribute('hidden');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment