2021年1月21日星期四

jQuery repeatable functions

I am new to jQuery and am trying to figure out how to repeat functions. As you can see from the code below when clicked on the button it will turn to 'I was clicked' in an h1 and then when clicked again it will go back to 'Click Me' however of course it stops after that. Without having to continuously write those lines over and over again, what is the easiest way to have it repeat so anytime I click on it it changes?

$("button").click(function() {    $(this).html("<h1>I was clicked</h1>");    $(this).click(function() {      $(this).html("Click Me")    })  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <h1>Hello</h1>  <button>Click Me</button>  <button>Click Me</button>  <button>Click Me</button>  <button>Click Me</button>  <button>Click Me</button>
https://stackoverflow.com/questions/65837764/jquery-repeatable-functions January 22, 2021 at 08:34AM

没有评论:

发表评论