jquery - How to set a div class depending on a variable value -


i trying set div class depending on variable set process.

the reason trying create dashboard type page show if servers or down among other things.

if there better way of doing happy try different option.

code (from comment):

<script>     var server.v1 = "down"  </script> <script>     var servers.v2 = "up"  </script>  <div id=servers>  <script>     if document.getelementbyid("servers").innerhtml = v2 == {          div class="componentsuccess"     } else {          div class="componentfail"     } </script> 

using jquery, tagged question with, it's pretty straight forward

var $mydiv = $(/* div */); var isvalid = /* code here check */ var classname = isvalid? 'valid' : 'invalid'; $mydiv.addclass(classname); 

obviously simplified example, you'll want toggle class , make sure doesn't both classes , on.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -