I am having an issue unsetting the offset of an element. Here is my code in jsfiddle: http://jsfiddle.net/hhQH2/39/
And here is my code:
HTML:
<div class="div" id="378246"></div>
<div class="promoBook" id="378246"></div>
<div class="availability"><div class="avClose">X</div></div>
<div class='tellme'></div>
CSS:
.promoBook{
margin-top: 100px;
margin-left: 100px;
background: #333;
width: 120px;
height: 45px;
color: #fff;
}
.availability{
position: absolute;
background: red;
width: 200px;
height: 150px;
display: none;
}
JQUERY:
//pop up availability
$(".promoBook").click(function(){
var btnavail = $(".availability");
var bookId = $(this).attr("id");
var btnpos = $(this).offset();
$(".tellme").text(btnpos.left + btnpos.top);
//change position of availability div
btnavail.offset(btnpos);
btnavail.show();
$(".avClose").click(function(){
btnavail.hide();
btnavail.offset({left:0,top:0});
});
});
The main problem is that it is not erasing the set offset… it holds the old one and adds the new. I hope this makes sense.. any help would be greatly appreciated!!
In the jQuery doc :
I believe it is the same when you want to set it 😉
To resolve your problem, just reverse the two lines of close method :