why does jQuery’s .html(“abc”) only insert temproarily?

  • 0
  • Pump00:00

i have an html button that calls a function, however when the buttons clicked, the inserted div only appears for a second and then disappears, both visually and in the html tree.

function openBox () {

$( '#0' ).click( function () {

    var container = 
    $( "<div>" ).css({
        height : "200px",
        width : "200px",
        position : "absolute",
        "background-color" : "black",
    });

     $( 'button.box' ).html( container );
});
}

if i insert the div created in JS into ‘button.box’ it displays only temporarily, for a split second. the html looks as such:

<div class="holder">
  <button id="0" class="box fa fa-paint-brush"></button>
</div>

but if inserted into ‘div.holder’ with the same html structure however, the box displays continuously as expected, but the button is gone.

What is the reason for the button disappearing with continuous display of box & the temporary display of box in their respective circumstances, and what can be done about the button disappearing?

Default Asked on February 7, 2020 in Programming.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.