I have some elements that I want to hide once document body is clicked. This code came from an answer given in Stack Overflow:
$(document).mouseup(function (e){
var container = $(".time-stamp, .full-name, .comment-box-wrapper .search-result");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // nor a descendant of the container
{
container.hide();
}
});
It works fine but my page displays 10 different articles at a time and each article has textbox (comment-box
) which are wrapped in comment-box-wrapper
and attached to each articles where users can
submit their comments. These comment boxes are set to hidden by default until a user clicks on Comment button. The problem is if a user has
entered some text in the comment box and clicks elsewhere, the comment-box
gets set to hidden
and the content is lost completely.
How can I cancel .hide()
if comment-box
already has some content in it?