How to Hide / Clear AJAX Search Suggestions After Clicking Somewhere Else

Posted in: Newspaper
Post count: 1

Figured out how to do this just thought I’d share the knowledge in question / answer format.

Paste this code in Theme Panel -> Custom Javascript


// Clear Ajax search
// from http://stackoverflow.com/questions/1403615/use-jquery-to-hide-a-div-when-the-user-clicks-outside-of-it
jQuery(document).mouseup(function (e)
{
var container = jQuery("#td-aj-search");

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.empty();
}
});

Viewing 1 post (of 1 total)
The forum ‘Newspaper’ is closed to new topics and replies.