Delay changing innerHTML text using jQuery

前端 未结 2 1317
自闭症患者
自闭症患者 2021-01-20 15:05

So I\'ve got a pretty simple button that basically toggles a form on and off - we\'ll be using this on our site since we\'re doing an update and would like feedback availabl

相关标签:
2条回答
  • 2021-01-20 15:45

    How about this:

       $(document).ready(function() {
    
          function changeText(){
            $("#myDiv").text('test')
          }
    
          setTimeout(changeText, 2000);
    
        });
    
    0 讨论(0)
  • 2021-01-20 15:56

    You can achieve this by using setTimeout():

    var timeout;
    $('#feedbackLink').hover(
        function() {
            clearTimeout(timeout);
            timeout = setTimeout(function() {
                $("#feedbackLink").html('Send us a quick message!');
            }, 2000); // change the HTML after 2 seconds
        },
        function() {
            clearTimeout(timeout);
            timeout = setTimeout(function() {
                $("#feedbackLink").html('How can we improve this page?');
            }, 2000); // change the HTML after 2 seconds
        }
    );
    
    0 讨论(0)
提交回复
热议问题