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
Post a Comment