Saturday 11 November 2017

javascript - How to close div clicking outside of it





Now I am closing the alert box when I clicked on the 'x' but I want
to close the alertbox when I click outside of
it.



Please see my code here : href="http://jsfiddle.net/Ur5Xn/" rel="nofollow">http://jsfiddle.net/Ur5Xn/



How to close alertbox clicking outside of
it?



The
jQuery:



$(document).ready(function(){


function showAlertBox(){
$("#alert").css("display","inherit");

$("#content").addClass("back");
}
function
removeAlertBox(){
$("#alert").css("display","none");

$("#content").removeClass("back");
}


$("#alertClose").click(function(){

removeAlertBox();

});
$("#alertShow").click(function(){
showAlertBox();

});
});

class="post-text" itemprop="text">
class="normal">Answer



try this
code




$(document).ready(function(){

function showAlertBox(){
$("#alert").css("display","inherit");

$("#content").addClass("back");
}
function
removeAlertBox(){
$("#alert").css("display","none");

$("#content").removeClass("back");
}



$("#alertClose").click(function(e){
e.stopPropagation();

removeAlertBox();
});

$("#alertShow").click(function(e){
e.stopPropagation();

showAlertBox();
});


$(document).click(function(e){

removeAlertBox();

});
});


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...