Last active
December 28, 2015 20:48
-
-
Save tomoyamkung/7559648 to your computer and use it in GitHub Desktop.
[JavaScript]タグに定義されている class を切り替える。
`isNullOrEmpty` は [[JavaScript]文字列が Null かブランクであるかを問い合わせる。](https://gist.github.com/tomoyamkung/7559383) で取り上げたスニペット。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* タグに定義されている 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