jquery html disappears on click event

前端 未结 2 471
春和景丽
春和景丽 2021-01-20 00:44

Please see the following code:


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

    Otherwise you can simply do a return false which will do both preventDefault and stop propagation

    $('#helloButton').click(function (e) {
    
        $('#hello').html('<div>hello world</div>');
        return false;
    });
    
    0 讨论(0)
  • 2021-01-20 01:28

    in order to prevent the form from posting, so that you can see your changes, you need to call preventDefault()

    $('#helloButton').click(function (e) {
        e.preventDefault();
        $('#hello').html('<div>hello world</div>');
    });
    
    0 讨论(0)
提交回复
热议问题