Maybe you guys can help me out with this, I've been struggling with it for the past 30 minutes.

Let's say I have four elements with the same class.

<div class="test">hi</div>
<div class="test">hey</div>
<div class="test">yo</div>
<div class="test">What's up</div>

How can I select the one that was clicked on?

I was able to get it work like this:

$('.test').click(function() {
    $(this).toggleClass("btn-danger btn-success");
});

However, I need it to fire without being clicked on success after an ajax call, so I need to be able to do something like this (failed attempts):

$('.test', this).toggleClass("btn-danger btn-success"); // This did not work

$(this).find('.test').toggleClass("btn-danger btn-success");  // Also did not work

Any suggestions? Thanks so much!!

Edit
Report