Skip to content

Instantly share code, notes, and snippets.

@ChrisMissal
Created October 18, 2009 22:49
Show Gist options
  • Save ChrisMissal/212914 to your computer and use it in GitHub Desktop.
Save ChrisMissal/212914 to your computer and use it in GitHub Desktop.
using a ternary operator to call one of two functions
// One of the reasons I like JavaScript:
function toggleTrait(trait, iconName) {
// some ugly code :)
((hasTrait) ? addIcon : removeIcon)(iconBar, iconName);
}
function addIcon(iconBar, iconName) {
iconBar.append($("<img/>").attr("src", "img/" + iconName + ".png"));
}
function removeIcon(iconBar, iconName) {
var selector = "[src*='" + iconName + "']";
iconBar.children(selector).replaceWith('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment