javascript - Change CSS class of a <div> using dojo -


i change element's css class depending on if statement.

this have:

html

<div data-dojo-attach-point="waiticon" class="rightnode"> 

css

.rightnode{   float: right;   height: 75px;   width: 60px;   margin-top: 20px; } .nowaiticon{   float: right;   height: 75px;   width: 60px;   margin-top: 34px; } 

js

if (value == 0){      domclass.remove(this.waiticon, "rightnode");      domclass.add(this.waiticon, "nowaiticon"); else{      domclass.remove(this.waiticon, "nowaiticon");      domclass.add(this.waiticon, "rightnode"); } 

the data-dojo-attach-point attribute works when creating template based widget.

most this not referring right object.

anyway here jsfiddle of dom-class works.

require( [     'dojo/dom',     'dojo/dom-class',     'dojo/domready!' ], function(dom, domclass) {     function swapcolor(  ){        if (value == 0){          domclass.remove('node', 'red');         domclass.add('node', 'green');         value = 1;       }       else{          domclass.remove('node', 'green');         domclass.add('node', 'red');         value = 0;       }       }     value = 0;      dom.byid("btn").onclick = swapcolor;   }); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -