javascript - Can you add a class to multiple elements in a single line of code? -


my current code requires 3 lines of code give these charts animation. there way define multiple elements in 1 line of code, this? i'm trying clean code , make easier others understand , less clutter better.

$('#container1,container2,container3').addclass('animated zoomindown'); 

$(document).ready(function() {      highcharts.chart('container1', {          chart: {              plotbackgroundcolor: null,              plotborderwidth: null,              plotshadow: false,              type: 'pie'          },          title: {              text: 'what grade in?'          },          tooltip: {              pointformat: '{series.name}: <b>{point.percentage:.1f}%</b>'          },          plotoptions: {              pie: {                  allowpointselect: true,                  cursor: 'pointer',                  datalabels: {                      enabled: true,                      format: '<b>{point.name}</b>: {point.percentage:.1f} %',                      style: {                          color: (highcharts.theme && highcharts.theme.contrasttextcolor) || 'black'                      }                  }              }          },          series: [{              name: 'percentage',              colorbypoint: true,              data: [{                  name: '9th',                  y: 0              }, {                  name: '10th',                  y: 16.7,                  sliced: true,                  selected: true              }, {                  name: '11th',                  y: 25              }, {                  name: '12th',                  y: 58.3              }]          }]      });  });
<script src="https://code.highcharts.com/modules/exporting.js"></script>  <script src="https://code.highcharts.com/highcharts.js"></script>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" />  <div id="container1" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>  <script>    $('#container1').addclass('animated zoomindown');  </script>  <div id="container2" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>  <script>    $('#container2').addclass('animated zoomindown');  </script>  <div id="container3" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>  <script>    $('#container3').addclass('animated zoomindown');  </script>

for selecting multiple elements id has common prefix try this:

$('[id^=container]') 

and use addclass method.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -