Reputation: 1
I am doing a careers page for a website, vacancies get listed on the page and when you click on it the job description pops up, the thing is i want it to close when you click elsewhere i got the first item to do so but the rest will not.
<div class="joblisting">
<a href="#" class="contact" id="job_id">
<div class="messagepop pop" id="menucontainer">
job_description
</div>
<p>click to read description...</p>
</a>
</div>
http://jsfiddle.net/ZZ2BS/2/ : here it is on jsFiddle.
Upvotes: 0
Views: 85
Reputation: 2368
Hide your popup element on click anywhere and use stopPropagation()
to exclude element itself.
var popup = documrnt.getElementById("popup_id");
document.addEventListener("click", function(){
popup.style.display = "none"
}, false);
popup.addEventListener("click", function(e){
e.stopPropagation();
});
Upvotes: 0
Reputation: 995
You have two elements with the same id. Use a class instead.
$(document).click(function(event) {
if($('.messagepop').is(":visible")) {
$('.messagepop').hide()
}
});
http://jsfiddle.net/philwills/ZZ2BS/4/
Upvotes: 1