I have a scenario where I want an event to happen when a button is clicked, but then I want a different behavior when it's clicked the second time. Here's an example of what's happening:
$('.click').not('.clicked').click(function () {
$(this).addClass('clicked');
$('<p class="test">Test</p>').insertAfter(this);
});
.clicked {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='button' class="click" value="Click Me" />
<input type='button' class="click clicked" value="Click Me" />
<input type='button' class="click" value="Click Me" />
What I want it to do is stop running the jQuery once the class .clicked is added to the button. This works the way I would expect, if the button already has the class applied, but if I add the class with jQuery it doesn't stop running my function each time the button is clicked.
$('.click').one()instead ...?