How to close a div by clicking outside anywhere?
up vote
5
down vote
favorite
I am working on alpha.dubaiexporters.com.
http://alpha.dubaiexporters.com/aboutus.aspx
There is a go button clicking on which a search panel appears where I can perform search keyword and category.
The issue is that after clicking on go button, search panel appears but if the user does not want to perform any search, he clicks outside anywhere but that search panel does not go.
I tried the following code where I have written javascript code but it didn't work.
<header class="header vc_row-fluid vc_col-sm-12">
<div class="top-header vc_col-sm-12">
<div class="logo shadows vc_col-sm-3">
<a href="Default.aspx"><img src="images/layout/check1.png" width="230" height="69" alt="Dubai Exporters" /></a></div>
<div class="menu-btn icon-menu-1"></div>
<div class="header_search"><div class="search sb-search" id="sb-search">
<div class="gray-form">
<input type="text" name="s" class="footer_search_input" onclick="clearInput(this, 'Search');" value="Search" />
<input type="submit" name="search" class="btn btn-primary sb-search-submit" value="Search" />
<span class="sb-icon-search">GO</span>
</div>
</div></div>
<div class="header-search-body">
<div class="header-search-container">
<div class="header-search-form">
<div class="header-form-container" id="mydiv">
<div class="header-input-container"><span class="header-input-title">Keyword:</span>
<input type="text" id="txtkeyword" name="s" runat="server" autocomplete="off">
<div class="clearfix"></div></div>
<div class="header-input-container"><span class="header-input-title">Category:</span>
<input type="text" id="txtserach" list="browsers" name="myBrowser" runat="server" autocomplete="off" causesvalidation="false">
<datalist id="browsers">
<option value="Automotive"/>
<option value="Building and Interiors"/>
<option value="Food, Kitchen and Hotel Supplies"/>
<option value="Industrial and Machinery"/>
<option value="Consumer and Household"/>
<option value="Medical and Healthcare"/>
<option value="Printing , Packaging and Plastic"/>
<option value="IT / Telecom / Electronics"/>
<option value="Oil and Gas"/>
<option value="Power and Energy"/>
</datalist>
<div class="clearfix"></div></div>
<input type="hidden" id="header-post-type" value="gd_place">
<asp:Button ID="Search" class="wpb_button wpb_btn-warning icon-search" style="top:0px;width:70px;height:70px;" Text="Search" runat="server" onclick="doit" OnClientClick="return checkLength();" UseSubmitBehaviour="false" CausesValidation="false" />
<script type="text/javascript">
function checkLength() {
var textbox = document.getElementById('<%=txtkeyword.ClientID%>');
var textbox1 = document.getElementById('<%=txtserach.ClientID%>');
if (textbox.value.length < 3 && textbox1.value.length == 0) {
alert("The entered input should be 3 or more than 3 characters");
return false;
}
}
</script>
<script type="text/javascript">
//window.onload = function () {
// var hideMe = document.getElementById('mydiv');
// document.onclick = function (e) {
// if (e.target.id !== 'mydiv') {
// // mydiv.style.display = 'none';
// }
// };
//};
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
}
});
});
</script>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<a href="http://cohhe.com/demo/sky/sky-directory/gd-login/" class="header-add-property wpb_button wpb_btn-primary wpb_regularsize">Add Your Listing</a>
<div class="top-menu-container ">
<div class="menu-style"><ul id="menu-menu-2" class="header-menu gd-menu-z">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-1759"><a href="Default.aspx">Home</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="advertize.aspx">Advertise</a></li>--%>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1760"><a href="exhibition.aspx">Exhibitions</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1764"><a href="dubaiexhibitions.aspx">Trade Fairs in U.A.E</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1761"><a href="exhibition.aspx">Trade Fairs Worldwide</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1762"><a href="addexhibition.aspx">Add Your Event</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1765"><a href="http://cohhe.com/demo/sky/sky-directory/right-sidebar/">Right sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1763"><a href="http://cohhe.com/demo/sky/sky-directory/left-sidebar/">Left sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1766"><a href="http://cohhe.com/demo/sky/sky-directory/typography-2/">Typography</a></li>--%>
</ul>
</li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="http://cohhe.com/demo/sky/sky-directory/blog/">Subscribe</a></li>--%>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="member_benefits.aspx">Memberships</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="aboutus.aspx">About us</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="http://cohhe.com/demo/sky/sky-directory/contact/">Contact</a></li>--%>
</ul></div> </div>
<div class="clearfix"></div>
</div>
<%--<div class="header-background-img"><img src="//cohhe.com/demo/sky/sky-directory/wp-content/uploads/2015/01/header_bg1.jpg" alt="Header bg" /></div>--%>
<div class="header-search-container">
<div id="main_header_bg">
<style type="text/css" media="all">#main_header_image { background: url('images/header02.jpg'); height:150px; background-size: cover !important; background-position: 100% !important; }</style>
</div>
<div id="main_header_image"></div>
</div>
</header>
javascript c#
add a comment |
up vote
5
down vote
favorite
I am working on alpha.dubaiexporters.com.
http://alpha.dubaiexporters.com/aboutus.aspx
There is a go button clicking on which a search panel appears where I can perform search keyword and category.
The issue is that after clicking on go button, search panel appears but if the user does not want to perform any search, he clicks outside anywhere but that search panel does not go.
I tried the following code where I have written javascript code but it didn't work.
<header class="header vc_row-fluid vc_col-sm-12">
<div class="top-header vc_col-sm-12">
<div class="logo shadows vc_col-sm-3">
<a href="Default.aspx"><img src="images/layout/check1.png" width="230" height="69" alt="Dubai Exporters" /></a></div>
<div class="menu-btn icon-menu-1"></div>
<div class="header_search"><div class="search sb-search" id="sb-search">
<div class="gray-form">
<input type="text" name="s" class="footer_search_input" onclick="clearInput(this, 'Search');" value="Search" />
<input type="submit" name="search" class="btn btn-primary sb-search-submit" value="Search" />
<span class="sb-icon-search">GO</span>
</div>
</div></div>
<div class="header-search-body">
<div class="header-search-container">
<div class="header-search-form">
<div class="header-form-container" id="mydiv">
<div class="header-input-container"><span class="header-input-title">Keyword:</span>
<input type="text" id="txtkeyword" name="s" runat="server" autocomplete="off">
<div class="clearfix"></div></div>
<div class="header-input-container"><span class="header-input-title">Category:</span>
<input type="text" id="txtserach" list="browsers" name="myBrowser" runat="server" autocomplete="off" causesvalidation="false">
<datalist id="browsers">
<option value="Automotive"/>
<option value="Building and Interiors"/>
<option value="Food, Kitchen and Hotel Supplies"/>
<option value="Industrial and Machinery"/>
<option value="Consumer and Household"/>
<option value="Medical and Healthcare"/>
<option value="Printing , Packaging and Plastic"/>
<option value="IT / Telecom / Electronics"/>
<option value="Oil and Gas"/>
<option value="Power and Energy"/>
</datalist>
<div class="clearfix"></div></div>
<input type="hidden" id="header-post-type" value="gd_place">
<asp:Button ID="Search" class="wpb_button wpb_btn-warning icon-search" style="top:0px;width:70px;height:70px;" Text="Search" runat="server" onclick="doit" OnClientClick="return checkLength();" UseSubmitBehaviour="false" CausesValidation="false" />
<script type="text/javascript">
function checkLength() {
var textbox = document.getElementById('<%=txtkeyword.ClientID%>');
var textbox1 = document.getElementById('<%=txtserach.ClientID%>');
if (textbox.value.length < 3 && textbox1.value.length == 0) {
alert("The entered input should be 3 or more than 3 characters");
return false;
}
}
</script>
<script type="text/javascript">
//window.onload = function () {
// var hideMe = document.getElementById('mydiv');
// document.onclick = function (e) {
// if (e.target.id !== 'mydiv') {
// // mydiv.style.display = 'none';
// }
// };
//};
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
}
});
});
</script>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<a href="http://cohhe.com/demo/sky/sky-directory/gd-login/" class="header-add-property wpb_button wpb_btn-primary wpb_regularsize">Add Your Listing</a>
<div class="top-menu-container ">
<div class="menu-style"><ul id="menu-menu-2" class="header-menu gd-menu-z">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-1759"><a href="Default.aspx">Home</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="advertize.aspx">Advertise</a></li>--%>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1760"><a href="exhibition.aspx">Exhibitions</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1764"><a href="dubaiexhibitions.aspx">Trade Fairs in U.A.E</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1761"><a href="exhibition.aspx">Trade Fairs Worldwide</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1762"><a href="addexhibition.aspx">Add Your Event</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1765"><a href="http://cohhe.com/demo/sky/sky-directory/right-sidebar/">Right sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1763"><a href="http://cohhe.com/demo/sky/sky-directory/left-sidebar/">Left sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1766"><a href="http://cohhe.com/demo/sky/sky-directory/typography-2/">Typography</a></li>--%>
</ul>
</li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="http://cohhe.com/demo/sky/sky-directory/blog/">Subscribe</a></li>--%>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="member_benefits.aspx">Memberships</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="aboutus.aspx">About us</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="http://cohhe.com/demo/sky/sky-directory/contact/">Contact</a></li>--%>
</ul></div> </div>
<div class="clearfix"></div>
</div>
<%--<div class="header-background-img"><img src="//cohhe.com/demo/sky/sky-directory/wp-content/uploads/2015/01/header_bg1.jpg" alt="Header bg" /></div>--%>
<div class="header-search-container">
<div id="main_header_bg">
<style type="text/css" media="all">#main_header_image { background: url('images/header02.jpg'); height:150px; background-size: cover !important; background-position: 100% !important; }</style>
</div>
<div id="main_header_image"></div>
</div>
</header>
javascript c#
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I am working on alpha.dubaiexporters.com.
http://alpha.dubaiexporters.com/aboutus.aspx
There is a go button clicking on which a search panel appears where I can perform search keyword and category.
The issue is that after clicking on go button, search panel appears but if the user does not want to perform any search, he clicks outside anywhere but that search panel does not go.
I tried the following code where I have written javascript code but it didn't work.
<header class="header vc_row-fluid vc_col-sm-12">
<div class="top-header vc_col-sm-12">
<div class="logo shadows vc_col-sm-3">
<a href="Default.aspx"><img src="images/layout/check1.png" width="230" height="69" alt="Dubai Exporters" /></a></div>
<div class="menu-btn icon-menu-1"></div>
<div class="header_search"><div class="search sb-search" id="sb-search">
<div class="gray-form">
<input type="text" name="s" class="footer_search_input" onclick="clearInput(this, 'Search');" value="Search" />
<input type="submit" name="search" class="btn btn-primary sb-search-submit" value="Search" />
<span class="sb-icon-search">GO</span>
</div>
</div></div>
<div class="header-search-body">
<div class="header-search-container">
<div class="header-search-form">
<div class="header-form-container" id="mydiv">
<div class="header-input-container"><span class="header-input-title">Keyword:</span>
<input type="text" id="txtkeyword" name="s" runat="server" autocomplete="off">
<div class="clearfix"></div></div>
<div class="header-input-container"><span class="header-input-title">Category:</span>
<input type="text" id="txtserach" list="browsers" name="myBrowser" runat="server" autocomplete="off" causesvalidation="false">
<datalist id="browsers">
<option value="Automotive"/>
<option value="Building and Interiors"/>
<option value="Food, Kitchen and Hotel Supplies"/>
<option value="Industrial and Machinery"/>
<option value="Consumer and Household"/>
<option value="Medical and Healthcare"/>
<option value="Printing , Packaging and Plastic"/>
<option value="IT / Telecom / Electronics"/>
<option value="Oil and Gas"/>
<option value="Power and Energy"/>
</datalist>
<div class="clearfix"></div></div>
<input type="hidden" id="header-post-type" value="gd_place">
<asp:Button ID="Search" class="wpb_button wpb_btn-warning icon-search" style="top:0px;width:70px;height:70px;" Text="Search" runat="server" onclick="doit" OnClientClick="return checkLength();" UseSubmitBehaviour="false" CausesValidation="false" />
<script type="text/javascript">
function checkLength() {
var textbox = document.getElementById('<%=txtkeyword.ClientID%>');
var textbox1 = document.getElementById('<%=txtserach.ClientID%>');
if (textbox.value.length < 3 && textbox1.value.length == 0) {
alert("The entered input should be 3 or more than 3 characters");
return false;
}
}
</script>
<script type="text/javascript">
//window.onload = function () {
// var hideMe = document.getElementById('mydiv');
// document.onclick = function (e) {
// if (e.target.id !== 'mydiv') {
// // mydiv.style.display = 'none';
// }
// };
//};
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
}
});
});
</script>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<a href="http://cohhe.com/demo/sky/sky-directory/gd-login/" class="header-add-property wpb_button wpb_btn-primary wpb_regularsize">Add Your Listing</a>
<div class="top-menu-container ">
<div class="menu-style"><ul id="menu-menu-2" class="header-menu gd-menu-z">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-1759"><a href="Default.aspx">Home</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="advertize.aspx">Advertise</a></li>--%>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1760"><a href="exhibition.aspx">Exhibitions</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1764"><a href="dubaiexhibitions.aspx">Trade Fairs in U.A.E</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1761"><a href="exhibition.aspx">Trade Fairs Worldwide</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1762"><a href="addexhibition.aspx">Add Your Event</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1765"><a href="http://cohhe.com/demo/sky/sky-directory/right-sidebar/">Right sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1763"><a href="http://cohhe.com/demo/sky/sky-directory/left-sidebar/">Left sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1766"><a href="http://cohhe.com/demo/sky/sky-directory/typography-2/">Typography</a></li>--%>
</ul>
</li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="http://cohhe.com/demo/sky/sky-directory/blog/">Subscribe</a></li>--%>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="member_benefits.aspx">Memberships</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="aboutus.aspx">About us</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="http://cohhe.com/demo/sky/sky-directory/contact/">Contact</a></li>--%>
</ul></div> </div>
<div class="clearfix"></div>
</div>
<%--<div class="header-background-img"><img src="//cohhe.com/demo/sky/sky-directory/wp-content/uploads/2015/01/header_bg1.jpg" alt="Header bg" /></div>--%>
<div class="header-search-container">
<div id="main_header_bg">
<style type="text/css" media="all">#main_header_image { background: url('images/header02.jpg'); height:150px; background-size: cover !important; background-position: 100% !important; }</style>
</div>
<div id="main_header_image"></div>
</div>
</header>
javascript c#
I am working on alpha.dubaiexporters.com.
http://alpha.dubaiexporters.com/aboutus.aspx
There is a go button clicking on which a search panel appears where I can perform search keyword and category.
The issue is that after clicking on go button, search panel appears but if the user does not want to perform any search, he clicks outside anywhere but that search panel does not go.
I tried the following code where I have written javascript code but it didn't work.
<header class="header vc_row-fluid vc_col-sm-12">
<div class="top-header vc_col-sm-12">
<div class="logo shadows vc_col-sm-3">
<a href="Default.aspx"><img src="images/layout/check1.png" width="230" height="69" alt="Dubai Exporters" /></a></div>
<div class="menu-btn icon-menu-1"></div>
<div class="header_search"><div class="search sb-search" id="sb-search">
<div class="gray-form">
<input type="text" name="s" class="footer_search_input" onclick="clearInput(this, 'Search');" value="Search" />
<input type="submit" name="search" class="btn btn-primary sb-search-submit" value="Search" />
<span class="sb-icon-search">GO</span>
</div>
</div></div>
<div class="header-search-body">
<div class="header-search-container">
<div class="header-search-form">
<div class="header-form-container" id="mydiv">
<div class="header-input-container"><span class="header-input-title">Keyword:</span>
<input type="text" id="txtkeyword" name="s" runat="server" autocomplete="off">
<div class="clearfix"></div></div>
<div class="header-input-container"><span class="header-input-title">Category:</span>
<input type="text" id="txtserach" list="browsers" name="myBrowser" runat="server" autocomplete="off" causesvalidation="false">
<datalist id="browsers">
<option value="Automotive"/>
<option value="Building and Interiors"/>
<option value="Food, Kitchen and Hotel Supplies"/>
<option value="Industrial and Machinery"/>
<option value="Consumer and Household"/>
<option value="Medical and Healthcare"/>
<option value="Printing , Packaging and Plastic"/>
<option value="IT / Telecom / Electronics"/>
<option value="Oil and Gas"/>
<option value="Power and Energy"/>
</datalist>
<div class="clearfix"></div></div>
<input type="hidden" id="header-post-type" value="gd_place">
<asp:Button ID="Search" class="wpb_button wpb_btn-warning icon-search" style="top:0px;width:70px;height:70px;" Text="Search" runat="server" onclick="doit" OnClientClick="return checkLength();" UseSubmitBehaviour="false" CausesValidation="false" />
<script type="text/javascript">
function checkLength() {
var textbox = document.getElementById('<%=txtkeyword.ClientID%>');
var textbox1 = document.getElementById('<%=txtserach.ClientID%>');
if (textbox.value.length < 3 && textbox1.value.length == 0) {
alert("The entered input should be 3 or more than 3 characters");
return false;
}
}
</script>
<script type="text/javascript">
//window.onload = function () {
// var hideMe = document.getElementById('mydiv');
// document.onclick = function (e) {
// if (e.target.id !== 'mydiv') {
// // mydiv.style.display = 'none';
// }
// };
//};
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
}
});
});
</script>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<a href="http://cohhe.com/demo/sky/sky-directory/gd-login/" class="header-add-property wpb_button wpb_btn-primary wpb_regularsize">Add Your Listing</a>
<div class="top-menu-container ">
<div class="menu-style"><ul id="menu-menu-2" class="header-menu gd-menu-z">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-1759"><a href="Default.aspx">Home</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="advertize.aspx">Advertise</a></li>--%>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1760"><a href="exhibition.aspx">Exhibitions</a>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1764"><a href="dubaiexhibitions.aspx">Trade Fairs in U.A.E</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1761"><a href="exhibition.aspx">Trade Fairs Worldwide</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1762"><a href="addexhibition.aspx">Add Your Event</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1765"><a href="http://cohhe.com/demo/sky/sky-directory/right-sidebar/">Right sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1763"><a href="http://cohhe.com/demo/sky/sky-directory/left-sidebar/">Left sidebar</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1766"><a href="http://cohhe.com/demo/sky/sky-directory/typography-2/">Typography</a></li>--%>
</ul>
</li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1767"><a href="http://cohhe.com/demo/sky/sky-directory/blog/">Subscribe</a></li>--%>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="member_benefits.aspx">Memberships</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="aboutus.aspx">About us</a></li>
<%--<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1768"><a href="http://cohhe.com/demo/sky/sky-directory/contact/">Contact</a></li>--%>
</ul></div> </div>
<div class="clearfix"></div>
</div>
<%--<div class="header-background-img"><img src="//cohhe.com/demo/sky/sky-directory/wp-content/uploads/2015/01/header_bg1.jpg" alt="Header bg" /></div>--%>
<div class="header-search-container">
<div id="main_header_bg">
<style type="text/css" media="all">#main_header_image { background: url('images/header02.jpg'); height:150px; background-size: cover !important; background-position: 100% !important; }</style>
</div>
<div id="main_header_image"></div>
</div>
</header>
javascript c#
javascript c#
edited Nov 10 at 14:43
halfer
14.2k757104
14.2k757104
asked Oct 12 at 9:07
chetan kambli
252110
252110
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22
add a comment |
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22
add a comment |
4 Answers
4
active
oldest
votes
up vote
2
down vote
accepted
You can achieve with the class names.
$(document).click(function (e) {
if(e.target != $(".sb-icon-search")[0] && (e.target.parentElement.parentElement != $(".header-form-container")[0])){
$(".header-search-body")[0].style.display = 'none';
}
});
$(".header_search").click(function (e) {
$(".header-search-body")[0].style.display = 'block';
});
it will be more easy way, if you use id instead of class names
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
add a comment |
up vote
1
down vote
First remove/rename class 'header-search-container' that you have used for header background (its used twice).
Then add event listeners or conditions on txtkeyword, textsearch and Search button.
Example:
// this will hide the search div
$(document).click(function (e) {
var id = e.target.id;
if(id !== 'ctl00_Search' && id !== 'ctl00_txtkeyword' && id !== 'ctl00_txtserach') {
$('.header-search-container')[0].style['display']='none';
}
});
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
|
show 3 more comments
up vote
1
down vote
My impression is that if condition is the root cause.
if (!$(e.target).is('[id*=Search]')) {...}
Can you try with below condition.
var $box = $('[id*=mydiv]');
//Condition to check if the target is the div or any of its children
// if false then hide the modal
if ($box.has(event.target).length == 0 && !$box.is(event.target) && !$('[name="search"]').is(event.target)) {
$box.attr('style', 'display:none');
}
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
add a comment |
up vote
0
down vote
The problem is that the click event is propagated up the dom, and then perform a click on the parent elements.
To prevent that you should return false on the eventhandlers:
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
return false;
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
return false;
}
});
});
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can achieve with the class names.
$(document).click(function (e) {
if(e.target != $(".sb-icon-search")[0] && (e.target.parentElement.parentElement != $(".header-form-container")[0])){
$(".header-search-body")[0].style.display = 'none';
}
});
$(".header_search").click(function (e) {
$(".header-search-body")[0].style.display = 'block';
});
it will be more easy way, if you use id instead of class names
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
add a comment |
up vote
2
down vote
accepted
You can achieve with the class names.
$(document).click(function (e) {
if(e.target != $(".sb-icon-search")[0] && (e.target.parentElement.parentElement != $(".header-form-container")[0])){
$(".header-search-body")[0].style.display = 'none';
}
});
$(".header_search").click(function (e) {
$(".header-search-body")[0].style.display = 'block';
});
it will be more easy way, if you use id instead of class names
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can achieve with the class names.
$(document).click(function (e) {
if(e.target != $(".sb-icon-search")[0] && (e.target.parentElement.parentElement != $(".header-form-container")[0])){
$(".header-search-body")[0].style.display = 'none';
}
});
$(".header_search").click(function (e) {
$(".header-search-body")[0].style.display = 'block';
});
it will be more easy way, if you use id instead of class names
You can achieve with the class names.
$(document).click(function (e) {
if(e.target != $(".sb-icon-search")[0] && (e.target.parentElement.parentElement != $(".header-form-container")[0])){
$(".header-search-body")[0].style.display = 'none';
}
});
$(".header_search").click(function (e) {
$(".header-search-body")[0].style.display = 'block';
});
it will be more easy way, if you use id instead of class names
edited Oct 12 at 11:33
answered Oct 12 at 11:17
Sandeep Bhaskar
13411
13411
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
add a comment |
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
....search panel goes if clicked outside ..now the issue is that there is header-input-container for keyword and category..so when user try to enter any input,search panel goes.
– chetan kambli
Oct 12 at 11:21
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
updated my answer can you once check now
– Sandeep Bhaskar
Oct 12 at 11:33
1
1
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
...Thats Worked Perfectly...Thank u so much...:)
– chetan kambli
Oct 12 at 11:39
add a comment |
up vote
1
down vote
First remove/rename class 'header-search-container' that you have used for header background (its used twice).
Then add event listeners or conditions on txtkeyword, textsearch and Search button.
Example:
// this will hide the search div
$(document).click(function (e) {
var id = e.target.id;
if(id !== 'ctl00_Search' && id !== 'ctl00_txtkeyword' && id !== 'ctl00_txtserach') {
$('.header-search-container')[0].style['display']='none';
}
});
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
|
show 3 more comments
up vote
1
down vote
First remove/rename class 'header-search-container' that you have used for header background (its used twice).
Then add event listeners or conditions on txtkeyword, textsearch and Search button.
Example:
// this will hide the search div
$(document).click(function (e) {
var id = e.target.id;
if(id !== 'ctl00_Search' && id !== 'ctl00_txtkeyword' && id !== 'ctl00_txtserach') {
$('.header-search-container')[0].style['display']='none';
}
});
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
|
show 3 more comments
up vote
1
down vote
up vote
1
down vote
First remove/rename class 'header-search-container' that you have used for header background (its used twice).
Then add event listeners or conditions on txtkeyword, textsearch and Search button.
Example:
// this will hide the search div
$(document).click(function (e) {
var id = e.target.id;
if(id !== 'ctl00_Search' && id !== 'ctl00_txtkeyword' && id !== 'ctl00_txtserach') {
$('.header-search-container')[0].style['display']='none';
}
});
First remove/rename class 'header-search-container' that you have used for header background (its used twice).
Then add event listeners or conditions on txtkeyword, textsearch and Search button.
Example:
// this will hide the search div
$(document).click(function (e) {
var id = e.target.id;
if(id !== 'ctl00_Search' && id !== 'ctl00_txtkeyword' && id !== 'ctl00_txtserach') {
$('.header-search-container')[0].style['display']='none';
}
});
answered Oct 12 at 9:48
Rishabh Kumar
355211
355211
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
|
show 3 more comments
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
....i tried above javascript....so when i click on go button,search panel appears and when i click outside anywhere,it goes...only issue is that when i am trying to enter keyword or category,search panel goes...
– chetan kambli
Oct 12 at 10:11
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@chetankambli did you first remove your jquery display none code ?
– Rishabh Kumar
Oct 12 at 10:13
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@rishabh...i removed the other div class..still the problem persists
– chetan kambli
Oct 12 at 10:24
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
@chetankambli I tried the same code on your website in the browser console and its working fine for me. Which browser are you using ?
– Rishabh Kumar
Oct 12 at 10:27
1
1
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
@chetankambli Yes chetan, its working fine for me.
– Rishabh Kumar
Oct 15 at 11:22
|
show 3 more comments
up vote
1
down vote
My impression is that if condition is the root cause.
if (!$(e.target).is('[id*=Search]')) {...}
Can you try with below condition.
var $box = $('[id*=mydiv]');
//Condition to check if the target is the div or any of its children
// if false then hide the modal
if ($box.has(event.target).length == 0 && !$box.is(event.target) && !$('[name="search"]').is(event.target)) {
$box.attr('style', 'display:none');
}
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
add a comment |
up vote
1
down vote
My impression is that if condition is the root cause.
if (!$(e.target).is('[id*=Search]')) {...}
Can you try with below condition.
var $box = $('[id*=mydiv]');
//Condition to check if the target is the div or any of its children
// if false then hide the modal
if ($box.has(event.target).length == 0 && !$box.is(event.target) && !$('[name="search"]').is(event.target)) {
$box.attr('style', 'display:none');
}
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
add a comment |
up vote
1
down vote
up vote
1
down vote
My impression is that if condition is the root cause.
if (!$(e.target).is('[id*=Search]')) {...}
Can you try with below condition.
var $box = $('[id*=mydiv]');
//Condition to check if the target is the div or any of its children
// if false then hide the modal
if ($box.has(event.target).length == 0 && !$box.is(event.target) && !$('[name="search"]').is(event.target)) {
$box.attr('style', 'display:none');
}
My impression is that if condition is the root cause.
if (!$(e.target).is('[id*=Search]')) {...}
Can you try with below condition.
var $box = $('[id*=mydiv]');
//Condition to check if the target is the div or any of its children
// if false then hide the modal
if ($box.has(event.target).length == 0 && !$box.is(event.target) && !$('[name="search"]').is(event.target)) {
$box.attr('style', 'display:none');
}
edited Oct 12 at 9:52
answered Oct 12 at 9:29
santosh
410310
410310
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
add a comment |
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
@santosh..it dint worked..after clicking on go,search panel appears but when i click on input type of keyword,it goes.When i click on go again,search panel does not come.
– chetan kambli
Oct 12 at 9:35
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
Can you try with new edit. it should work :)
– santosh
Oct 12 at 9:40
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
@santosh...now after clicking on go...search panel does not appears.
– chetan kambli
Oct 12 at 9:43
add a comment |
up vote
0
down vote
The problem is that the click event is propagated up the dom, and then perform a click on the parent elements.
To prevent that you should return false on the eventhandlers:
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
return false;
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
return false;
}
});
});
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
add a comment |
up vote
0
down vote
The problem is that the click event is propagated up the dom, and then perform a click on the parent elements.
To prevent that you should return false on the eventhandlers:
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
return false;
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
return false;
}
});
});
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem is that the click event is propagated up the dom, and then perform a click on the parent elements.
To prevent that you should return false on the eventhandlers:
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
return false;
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
return false;
}
});
});
The problem is that the click event is propagated up the dom, and then perform a click on the parent elements.
To prevent that you should return false on the eventhandlers:
$(function () {
$("[id*=Search]").click(function (e) {
$("[id*=mydiv]").attr('style', 'display:block');
return false;
});
$(document).click(function (e) {
if (!$(e.target).is('[id*=Search]')) {
$("[id*=mydiv]").attr('style', 'display:none');
return false;
}
});
});
answered Oct 12 at 9:45
Poul Bak
4,8823732
4,8823732
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
add a comment |
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
..i tried above javascript.. after clicking on go button,search panel does not comes.
– chetan kambli
Oct 12 at 9:54
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52776061%2fhow-to-close-a-div-by-clicking-outside-anywhere%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Side note: i'm sure somebody smarter than me can perform a XSS on this site, I'd look into it OP, you're not encoding your search string.
– Matt
Oct 12 at 9:22