SmokeTM
1 year ago

Change button color after ajax request

Posted 1 year ago by SmokeTM

Is there a more efficient way to change the button color after ajax request? Or is this the way to go?

$buttonColor = '';

        if($user->votedFor($article)) {
          $user->unvoteFor($article);
          $buttonColor = 'black';
        } else {
          $user->voteFor($article);
          $buttonColor = '#38c172';
        }

        return response()->json(['success' => true, 'count' => $article->fresh()->votes->count(), 'color' => $buttonColor]);

Please sign in or create an account to participate in this conversation.