In $ (document) .ready (), I create a model popup for adding elements to the page, and it works great when the page loads for the first time, but it does not show a modal popup if it is called at least once, therefore, please tell me where am i doing something wrong that it does not show a modal view?
OR
Is jquery ready () called only once when the page loads?
here is jQuery:
$(document).ready(function () {
$('a[name=modal]').click(function (e) {
e.preventDefault();
var id = $(this).attr('href');
var maskHeight = $(document).height();
var maskWidth = $(window).width();
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
var winH = $(window).height();
var winW = $(window).width();
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
$(id).fadeIn(2000);
var htmlStr = $("#divErrorMsg").html();
if (htmlStr != null && htmlStr.length > 0) {
htmlStr = null;
$("#divErrorMsg").text('');
}
});
});
and here is the link where the popup is called:
<a name="modal" href="#iPopup" class="button smallButton">Add Item</a>
and iPopup:
<div id="Popups">
<div id="iPopup" class="popup">
<a class="closeButton">x</a>
<div class="popupContent">
<h3>Choose a question type</h3>
<ul class="chooseQuestion">
<li>
<div class="short">
<label>Question 1</label>
<input />
<p class="description">Eg. This is a description.</p>
</div>
<%= Ajax.ActionLink("Text", "action", new { id = tId }, new AjaxOptions() { UpdateTargetId = "tItems" }, new { @class = "button" })%>
</li>
<li>
<div class="short">
<label>Question 2</label>
<input />
<p class="description">Eg. This is a description.</p>
</div>
<%= Ajax.ActionLink("Text", "action", new { id = tId }, new AjaxOptions() { UpdateTargetId = "tItems" }, new { @class = "button" })%>
</li>
</ul>
</div>
</div>
<div id="mask"></div>
</div>
source
share