I am working in a single page with multiple anchors. Each anchor has separate content to popup when clicked. I have the functionality working but when I click a different anchor it repeats the same content from the first anchor. I need to have each anchor show the corresponding content in the popup. Below is my code. Thank you in advance.
<script>
$(document).ready(function() {
$('a.bio, a.bio2').click(function() {
//Getting the variable's value from a link
var loginBox = $(this).attr('href');
//Fade in the Popup
$(loginBox).fadeIn(300);
//Set the center alignment padding + border see css style
var popMargTop = ($(loginBox).height() + 24) / 2;
var popMargLeft = ($(loginBox).width() + 24) / 2;
$(loginBox).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
return false;
});
// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function() {
$('#mask , .login-popup').fadeOut(300 , function() {
$('#mask').remove();
});
return false;
});
});
</script>
The HTML
<a class="bio" href="#login-box">READ BIO >></a>
<div class="login-popup" id="login-box">
<div id="popupimage">
<h2>This is image 1</h2>
</div></div>
<a class="bio2" href="#login-box">READ BIO >></a></div>
<div class="login-popup" id="login-box">
<div id="popupimage">
<h2>This is image 2</h2>
</div></div>
The CSS
.login-popup {
background: none repeat scroll 0 0 #585858;
display: none;
float: left;
font-size: 1.2em;
height: 350px;
left: 50%;
padding: 20px;
position: fixed;
top: 50%;
width: 500px;
z-index: 999999999;
color:#FFF;
}
An html document can have a single element with an id. You have two div with login-box id. You must specify unique ids to each of them: