title: How to hide an element or div if a string is null?
body: <p>I have a website that uses server-generated JSON objects to populate its content. I want to implement optional text descriptions for images which only appear if an image has a description. I tried to do this by assigning the description contained in a JSON object to a string and checking if the string equals "null" or not, but this didn't work. Here is my code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;p id="image-description"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>JavaScript: </p>
  
  <pre><code>// Note: I'm not trying to populate the innerHTML of &lt;p&gt; with the content 
  // of `descriptionString` here 
  
  // At beginning of script:
  var descriptionString = ''
  
  // Inside function that populates website with content from JSON object:
  parsedJSON = JSON.parse(this.responseText);
  
  descriptionString = parsedJSON['activities'][0]['description'];
  if (descriptionString != 'null') {
      document.getElementById('image-description').style.display = 'block';
  } else {
      document.getElementById('image-description').style.display = 'none';
  }
  </code></pre>
  
  <p>The <code>image-description</code> element always appears with this code, even when <code>descriptionString</code> is <code>'null'</code>. I also tried using <code>.style.visibility = 'visible';</code> and <code>.style.visibility = 'hidden';</code> as well as putting the element in a div, but they all produced the same result. Moreover, when I set a default style for <code>image-description</code> with CSS and tried to modify it with JavaScript it wouldn't change.</p>
  
  <p>I've confirmed that the string from <code>parsedJSON</code> is being properly assigned to <code>descriptionString</code> (and assigns <code>'null'</code> when no string is present) so I must be doing something else wrong. </p>
  
  <p>I haven't found any other answers that address this exact scenario, and I am trying not to use external libraries like jQuery. What is the best way to solve this with pure JavaScript?</p>