Your first code sample doesn't really change the style but it declares it when you create the element.
You probably want to set the style when you create your element. Following code will set background color of created element to black if mymonth is 1, else it will be orange.
echo "<span id='m01' class='badge' style='background-color: ".(mymonth === 1 ? "black" : "orange")."'><a href=''>january</a></span>";
document.getElementById("m'.(mymonth < 10 ? "0" : "").mymonth.'").style.background-color = "black";