If you have thousands of such elements then may be you feel any performance difference.
But of course. If your button type is 'checkbox' and if you don't make any function to manipulate that type of button, all can be done at CSS. If you preferred to do that and it works for you, it's all OK.
Its only OK if I can get this structure to work with your controller.
Just to reiterate how I came across the structure which works for divs or spans. This structure was the only one out of dozens that I tried over the course of last week.
<md-button class="md-button ck-button on off small"
data-payload="1"
data-state="1"
data-buttontype='checkbox'
data-radiogroup='group1'
data-topic="11">
<label class="ck-switch">
<input type="checkbox" unchecked>
<span style="background-color:#097479);" class="on">radio<br>group1<br><br>btn 11<br>with a lot more text fun<br>on</span>
<span style="background-color:#003333;" class="off">radio<br>group1<br><br>btn 11<br>off</span>
</label>
</md-button>
To control the rendering all I need to do is set the checkbox value to true or false (which I know how to do from within setButtonState()).
I can successfully change the values in this template using:
function processCommand($btn, payload){
//first check payload is correct format...
//{"selector":".remote-button3x-on","command":"setContent","value":"HELLO"}
if(!payload || !payload.command || !payload.value){
console.log("Cannot process command. Expected a payload object with .command and .value. ")
}
var cmd = payload.command.trim();
switch(cmd){
case "addClass":
$btn.addClass(payload.value); //this calls the jquery function by name (specified in .command) on the $btn and passes in .value
break;
case "toggleClass":
$btn.toggleClass(payload.value); //this calls the jquery function by name (specified in .command) on the $btn and passes in .value
break;
case "setColour":
var spanSelector = payload.selector.trim();
var $span = $btn.find(spanSelector);//get the span
console.log("$spanBefore=" + $span.text() + " $spanBefore=" + payload.value);
$span.css({"background-color": payload.value});
//$btn.text("Hello world!");
// $btn.toggleClass(payload.value); //this calls the jquery function by name (specified in .command) on the $btn and passes in .value
break;
case "setContent":
var spanSelector = payload.selector.trim();
var $span = $btn.find(spanSelector);//get the span
console.log("$spanBefore=" + $span.text() + " $spanBefore=" + payload.value);
$span.text(payload.value);
//$btn.text("Hello world!");
// $btn.toggleClass(payload.value); //this calls the jquery function by name (specified in .command) on the $btn and passes in .value
break;
case "removeClass":
$btn.removeClass(payload.value); //this calls the jquery function by name (specified in .command) on the $btn and passes in .value
break;
default:
console.log("command '" + payload.command + "' is not supported")
}
}
Although I have a jsfiddle using a single span with no input checkbox or additional wrappers. The text renders perfect but not when it is nested in md. The extra wrappers seem necessary in order to insulate the css. http://jsfiddle.net/c2e8rykt/2/
So make your button without wrapping it into md-button. You need probably deal with pointer-events and cursor ant may be some visual properties for the div. And you will lose the ripple animations from md-button.
<div style="height: 200px; width: 100px;" class="remote-button">
<span style="color: white; background-color: #009900;" class="onoff">Node red line that may overflow the 1234 width of the button<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off<br>off</span>
</div>
Start with getting rid of md-button. You will lose all what was given by md-button class. So you'll need to make css for ck-button to make it look like button first. That will be quite of styling. As you still can have data parameters, you can control it with same functionality but of course, some additions needed to make proper decisions about internal elements of your new button.
<div class="ck-button on off small"
data-payload="1"
data-state="1"
data-buttontype='checkbox'
data-radiogroup='group1'
data-topic="11">
<label class="ck-switch">
<input type="checkbox" unchecked>
<span style="background-color:#097479);" class="on">radio<br>group1<br><br>btn 11<br>with a lot more text fun<br>on</span>
<span style="background-color:#003333;" class="off">radio<br>group1<br><br>btn 11<br>off</span>
</label>
</div>
My current css styles ck-button and remote-button the same.
I am all for bear metal when it comes to css but you are telling me to start again from scratch after a week in control hell folowed by a week in css hell.
I am unable to do what you suggest. It is too complicated when one cannot see the big picture.
Can you show an example of a non md button using the css and html above ?
If it is not trivial to you it will be impossible to me.
I'd like to have some other suggestions with no work needed to be done but sadly there isn't any. If you need to have certain structure, you'll need to create it. That's why hand made things cost much more than fabricated stuff.