About jQuery append() and how to check if an element has been appended

前端 未结 6 1082
天命终不由人
天命终不由人 2021-01-11 10:21

I made a very simple button click event handler, I would like to have

element be appended when button clicked, you can check my code

6条回答
  •  我在风中等你
    2021-01-11 11:03

    http://jsfiddle.net/j36ye/17/

    $("#search_btn").click(function(){
        if(($('#other').length) == 0) {
            $("#wrapper").append("

    I am here

    "); } return false });

    Or

    var other_appended = false;
    
    $("#search_btn").click(function(){
        if(other_appended == false) {
             $("#wrapper").append("

    I am here

    "); other_appended = true; } return false; });

提交回复
热议问题