title: When dynamically creating HTML elements with jQuery, how to include values conditionally in the JSON?
body: <p>I'm creating a checkbox for every item in an XML file. The text of each file is <code>"TRUE"</code> or <code>"FALSE"</code>, and I want to create a checked checkbox for every <code>"TRUE"</code> and an unchecked checkbox for every <code>"FALSE"</code>. Right now my code is duplicated inside an if and an else because I can't think of a way to conditionally include the checked parameter in that JSON. Does anybody know a more DRY way to accomplish the same thing?</p>
  
  <pre><code>d = $(this)
  if (d.text() === 'TRUE') {
      $('&lt;input&gt;', {
      className: 'checkbox',
      type: 'checkbox',
      id: d.attr('id'),
      name: d.attr('name'),
      checked: 'checked'
      }).appendTo(td);
  }
  else {
      $('&lt;input&gt;', {
      className: 'checkbox',
      type: 'checkbox',
      id: d.attr('id'),
      name: d.attr('name')
      }).appendTo(td);
  }
  </code></pre>