title: How to change attr on condition using jQuery
body: <p>I have this html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;style type="text/css"&gt;
      [data-Status = "Used"]{
          background-color: green;
      }
  
      [data-Status = "Inactive"]{
          background-color: red;
      }
  
      [data-Status = "Active"]{
          background-color: gray;
      }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div&gt;
      &lt;input type="checkbox" onclick="Changestatus('Combo_1')" id="Combo_1" /&gt;
      &lt;div class="Combo_1 Activity_1" id="Activity_1" data-Status="Active"&gt;Activity_1&lt;/div&gt;
      &lt;div class="Combo_1 Activity_2" id="Activity_2" data-Status="Active"&gt;Activity_2&lt;/div&gt;
      &lt;div class="Combo_1 Activity_3" id="Activity_3" data-Status="Active"&gt;Activity_3&lt;/div&gt;
      &lt;div class="Combo_1 Activity_5" id="Activity_5" data-Status="Active"&gt;Activity_5 C3&lt;/div&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;input type="checkbox" onclick="Changestatus('Combo_2')" id="Combo_2"/&gt;
      &lt;div class="Combo_2 Activity_1" id="Activity_1" data-Status="Active"&gt;Activity_1 C1&lt;/div&gt;
      &lt;div class="Combo_2 Activity_3" id="Activity_3" data-Status="Active"&gt;Activity_3 C1&lt;/div&gt;
      &lt;div class="Combo_2 Activity_4" id="Activity_4" data-Status="Active"&gt;Activity_4 C3&lt;/div&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;input type="checkbox" onclick="Changestatus('Combo_3')" id="Combo_3"/&gt;
      &lt;div class="Combo_3 Activity_4" id="Activity_4" data-Status="Active"&gt;Activity_4 C2&lt;/div&gt;
      &lt;div class="Combo_3 Activity_5" id="Activity_5" data-Status="Active"&gt;Activity_5 C1&lt;/div&gt;
      &lt;div class="Combo_3 Activity_6" id="Activity_6" data-Status="Active"&gt;Activity_6&lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have to change attribute of common activity on checkbox check</p>
  
  <p><strong>For Example</strong> </p>
  
  <p>I checked <strong>Combo_1</strong> so this <strong>data-Status</strong> change into <strong>Used</strong> and other combos common activity <strong>data-Status* should change into **Inactive</strong> if i uncheck this Combo then all common <strong>[data-Status=Inactive]</strong> should change into <strong>[data-Status=Active]</strong>;</p>
  
  <p><strong>This Code i have written and it works but is there any easiest way to do that</strong>  </p>
  
  <pre><code>function Changestatus(element){
      var Active_Class = $('.'+element);
      if ($('#'+element).prop("checked") == true) {
  
          for(var i = 0; i &lt; Active_Class.length; i++){
              if ($(Active_Class[i]).attr("data-Status") == 'Active') {
                  $(Active_Class[i]).attr("data-Status", "Used");
              };
          }
  
          $('.'+element).each(function() {
              var elem_id = this.id;
              var Active_ID_Class = $('.'+elem_id);
              for(var i = 0; i &lt; Active_ID_Class.length; i++){
                  if ($(Active_ID_Class[i]).attr("data-Status") == 'Active') {
                      $(Active_ID_Class[i]).attr("data-Status", "Inactive");
                  };
              }
  
          });
      }
  
      else if ($('#'+element).prop("checked") == false){
  
          for(var i = 0; i &lt; Active_Class.length; i++){
              if ($(Active_Class[i]).attr("data-Status") == 'Used') {
                  $(Active_Class[i]).attr("data-Status", "Active");
              };
          }
  
          $('.'+element).each(function() {
              var elem_id = this.id;
              var Active_ID_Class = $('.'+elem_id);
              var Used_Activiy = false;
  
              for(var i = 0; i &lt; Active_ID_Class.length; i++){
                  if ($(Active_ID_Class[i]).attr("data-Status") == 'Used') {
                      Used_Activiy = true;
                  };
              }
              if (Used_Activiy != true) {
                  for(var i = 0; i &lt; Active_ID_Class.length; i++){
                      $(Active_ID_Class[i]).attr("data-Status", "Active");
                  }
              };
  
          });
      }
  }
  </code></pre>
  
  <p><strong>At least select two combo to understand my question</strong></p>