function placeGroupButtons() { $.post("API/getGrouprole.php", { grp: groupID }) .done(function(data) { var $buttonContainer = $("div.group-button-container"); if (data == 'none') { $buttonContainer.append( ""); } else if (data == 'request') { $buttonContainer.append( ""); } else if (data == 'admin') { $buttonContainer.append( "" ); } else { $buttonContainer.append( ""); } $buttonContainer.children().click(function() { if (this.value == 'admin') { window.location.href='groupAdmin.php?groupID=' + groupID; } else { $.post("API/editMembership.php", {grp: groupID, role: this.value}) .done(function () { $buttonContainer.children().remove(); placeGroupButtons(); updateMenus(); }).fail(function () { }); } }); }); }