[JavaScript]タグに定義されている class を切り替える。 `isNullOrEmpty` は [[JavaScript]文字列が Null かブランクであるかを問い合わせる。](https://gist.github.com/tomoyamkung/7559383) で取り上げたスニペット。
/** | |
* タグに定義されている class を切り替える。 | |
* | |
* to が定義されていない、もしくはブランクの場合は from の class を取り除く。 | |
* | |
* @param {String} id 切り替える class が定義されているタグの ID 属性 | |
* @param {String} from 切り替え対象の class | |
* @param {String} to 切り替える class | |
* @returns {} | |
*/ | |
function toggleClass(id, from, to) { | |
if(isNullOrEmpty(to)) { | |
$(id).removeClass(from); | |
return; | |
} | |
$(id).removeClass(from).addClass(to); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment