Neo
Neo

Reputation: 1037

Remove div on clicking anywhere

Trying to remove an appended div, I've tried .empty() and contents().remove();

I've commented out the removed code, see: http://jsfiddle.net/2Aw23/2/

Upvotes: 0

Views: 686

Answers (3)

dnuttle
dnuttle

Reputation: 3830

Is this what you want?

JS fiddle demo

It will add the div when the button is clicked, but then remove it when anything else is clicked. But note that other code may also specify that clicks on other parts of the page should stop propagation, so if that is the case, clicking those elements also will not remove the div.

Upvotes: 2

Huangism
Huangism

Reputation: 16438

you use the same functionality as Tadej mentioned but use it on the container div, and your button, you need to put it outside of that container and use absolute position to make it go to the right place i am sure there is a jquery way around this but the css way works too

Upvotes: 0

Tadej Magajna
Tadej Magajna

Reputation: 2963

$(document).click(function(e) {  
    $('#tip').remove();
});

Upvotes: 0

Related Questions