//UPDATE: nevermind I'm dumb. It works, but I'll change it to if/else
I have an ajax function and on success it'll update some css styles. If valueExists is true, I'd like to add multiple css styles and I place these css styles in a function
.success(function(data) {
data.valueExists ? multipleChanges($("#element")) : $("#element").addClass("classStyleTwo");
});
//Outside of success function multiple css changes
function multipleChanges(element){
$(element).addClass("classStyleTwo");
$(element).css({color: "#1abc9c"});
}
The problem is that the ternary is in an async request, so the function multipleChanges is called instantly. I'm still a bit rusty on callback functions I tried placing multipleChanges inside another function like...
function wrapper (cb, element){
return cb(element);
}
.success(function(data) {
data.valueExists ? wrapper(multipleChanges, $("#element")) : $("#element").addClass("classStyleTwo");
});