javascript - css only appends to the first panel -


i have wrote jquery change button colour red when 1 clicks on it. work first panel not working rest of panels. in first set of button works not everything. jquery part.

function durationonclick(element){     var buttonid = element.id;     var buttonname = element.name;     var buttonids = ["1hour", "30min", "1day" , "1week", "1month"];     var charttype = $('#charttype').val();     var idvalue = $('#idvalue').val();              //after user click option here changing option black red.     $(buttonids).each(function(i, e) {        $('#'+e+'[name='+buttonname+']').css("color", "");           });      $('#'+buttonid+'[name='+buttonname+']').css("color", "blue");         ` 

the html code :

<div class="row">     <div class="col-md-6">         <div class="panel panel-default">             <div class="panel-heading">                 <h3 class="panel-title" style="color:black">memory consumption average</h3>             </div>             <div class="panel-body">                 <button class="btn btn-default btn-xs" name="memoryconsumption" id="30min" onclick="return durationonclick(this)">30 mins</button>                 <button class="btn btn-default btn-xs" name="memoryconsumption" id="1hour" style="color:red" onclick="return durationonclick(this)">1 hour</button>                 <button class="btn btn-default btn-xs" name="memoryconsumption" id="1day" onclick="return durationonclick(this)">1 day</button>                 <button class="btn btn-default btn-xs" name="memoryconsumption" id="1week" onclick="return durationonclick(this)">1 week</button>                 <button class="btn btn-default btn-xs" name="memoryconsumption" id="1month" onclick="return durationonclick(this)">1 month</button>                 <div class="container content" style="width: 600px;">                     <div class="row text-center" id="chart3">                     </div>                 </div>             </div>         </div>     </div>      <div class="col-md-6">         <div class="panel panel-default">             <div class="panel-heading">                 <h3 class="panel-title" style="color:black">load average</h3>             </div>             <div class="panel-body">                 <button class="btn btn-default btn-xs" name="loadaverage" id="30min" onclick="return durationonclick(this)">30 mins</button>                 <button class="btn btn-default btn-xs" name="loadaverage" id="1hour" style="color:red" onclick="return durationonclick(this)">1 hour</button>                 <button class="btn btn-default btn-xs" name="loadaverage" id="1day" onclick="return durationonclick(this)">1 day</button>                 <button class="btn btn-default btn-xs" name="loadaverage" id="1week" onclick="return durationonclick(this)">1 week</button>                 <button class="btn btn-default btn-xs" name="loadaverage" id="1month" onclick="return durationonclick(this)">1 month</button>                 <div class="container content" style="width: 600px;">                                             <div class="row text-center" id="chart2">                     </div>                 </div>             </div>         </div>     </div> </div> 

after removing first panel colour changing happen next immediate chart charts below 1 changing colour not happening. figure out issue appreciated.

please use below code. work perfect case:-

 function durationonclick(ref) {      var buttonname = $(ref).attr("name");      $("button[name=" + buttonname + "]").each(function () {         $(this).css("color", "");     });      $(ref).css("color", "blue");    } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -