title: Javascript set data-required attribute
body: <p>I am trying to use the <code>data-required</code> attribute according to data,if <code>value == 1</code> I want to set the <code>data-required</code> attribute to <code>true</code> else <code>false</code> .</p>
  
  <p><strong>Html:</strong></p>
  
  <pre><code>&lt;input type="text" id="txtPhone" name="phone" data-required="true" class="form-control"&gt;
  </code></pre>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code> var value = $("#txtPhone").val();
          if (value == "1") {
              $("#txtPhone").... // Set data required true for txtphone input
          }
          else {
              $("#txtPhone")... // Set data required false for txtphone input
          }
  </code></pre>
  
  <p>How can I set <code>data-required</code> to true or false?</p>
  
  <p>How can i do this by JavaScript?</p>