Skip to content

Instantly share code, notes, and snippets.

@qqpann
Last active January 10, 2018 08:10
Show Gist options
  • Save qqpann/f13d4e299fb98cece0e3638d9e9a65ac to your computer and use it in GitHub Desktop.
Save qqpann/f13d4e299fb98cece0e3638d9e9a65ac to your computer and use it in GitHub Desktop.
CSS JS | change class button
<button onclick="book()">図書</button>
<button onclick="mgzn()">雑誌</button>
<h2>図書</h2>
<div id="book" class="red-card">
<p>
Book book book.
</p>
</div>
<script src="switch-class.js" type="text/javascript"></script>
function chClassName(idnm, classnm) {
document.getElementById(idnm).className = classnm;
}
function book() {
chClassName('book', 'red-card');
chClassName('mgzn', 'red-card-disabled');
}
function mgzn() {
chClassName('book', 'red-card-disabled');
chClassName('mgzn', 'red-card');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment