Inserting this line of code before .hide() fulfilled my requirement.
if ($(this).parent().is(":visible")) {
$(this).hide();
}
else {
$(this).show();
}
solved search script in jquery