Reputation: 61
i have here an on/off button,
$(document).ready(function(){
$("#onOffButton").on("click", function(){
$("#onOffButton").text("ON");
});
})
When i click back, i want to change the button to Off.
Upvotes: 0
Views: 551
Reputation: 28414
Try this:
$(document).ready(function(){
$("#onOffButton").on("click", function(){
var txt = $(this).text();
$(this).text(txt=="ON"?"OFF":"ON");
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="onOffButton">OFF</button>
Upvotes: 2