jQuery addClass example
Change class name on click in jQuery
HTML
<div id="banner-message">
<div id="output"></div>
<button>Run the Master Control Program</button>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: "Courier New", monospace;
}
#banner-message {
background: #888;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #444;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #040;
color: #0f0;
margin-top: 40px;
width: 90%;
border:2px solid #020;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
#output { font-size:0.6em; text-align:left }
JavaScript
// output display
var banner = $("#banner-message")
var button = $("button")
var mcptitle = $("mcptitle")
button.on("click", function(){
if (typeof MCPOutput == 'undefined')
{ MCPOutput = "Error: MCPOutput is not defined. MCP code must be copied from the ruleset into the Javascript window."; }
banner.addClass("alt")
button.css({ display: "none" });
document.getElementById("output").innerHTML = MCPOutput;
})