title: How to add a required attribute?
body: <p>I have a script that shows some and hides some html but I dont know how to add the required tag when it is shown, I have already tried to add the attribute in the section that I want it but it requires it even when not shown... can someone help me out. thanks in advance!</p>
  
  <pre><code>&lt;div  class="start"&gt;&lt;select name="start" class="form-control"&gt;
             &lt;option value="0" class="select"&gt;Select City&lt;/option&gt;
                  &lt;?php foreach($rows as $row): ?&gt; 
                      &lt;option &lt;? echo 'value="'.$row['id'].'"';
                          echo ($row['id'] == $job['start'])?' selected&gt;':'&gt;'; 
                          echo $row['name']; ?&gt;&lt;/option&gt;
                  &lt;?php endforeach; ?&gt;
              &lt;/select&gt;&lt;/div&gt;&lt;br /&gt;
              &lt;br /&gt;
              &lt;script&gt;
              $('select[name=start]').change(function () {
                  if ($(this).val() == '89') {
                      $('#otherStart').show();
                  } else {
                      $('#otherStart').hide();
                  }
              });
              &lt;/script&gt;
              &lt;br /&gt;
              &lt;div id="otherStart"&gt;
                  &lt;input type="text" name="otherStart" placeholder="Other City" &lt;? echo ($job['otherStart'])?' value="'.$job['otherStart'].'"':''; 
              ?&gt; class="form-control" &gt;
              &lt;/div&gt;
  </code></pre>