Reputation: 89
I have found this JavaScript code for a popup below. It is working properly. But I need to continue load that popups without exit (as a circle). So how can I add a loop to the button.
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if (pNode.prev(".modalDialog")) {
var id = pNode.prev(".modalDialog").attr("id");
window.location.href = "#" + id;
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if (pNode.next(".modalDialog")) {
var id = pNode.next(".modalDialog").attr("id");
window.location.href = "#" + id;
}
});
});
Upvotes: 2
Views: 88
Reputation: 392
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.prev(".modalDialog")){
var id = pNode.prev(".modalDialog").attr("id");
if (id != undefined)
window.location.href = "#" + id;
else {
var id = $(".modalDialog").last().attr("id");
window.location.href = "#" + id;
}
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.next(".modalDialog")){
var id = pNode.next(".modalDialog").attr("id");
if (id != undefined)
window.location.href = "#" + id;
else {
var id = $(".modalDialog").first().attr("id");
window.location.href = "#" + id;
}
}
});
});
Upvotes: 2
Reputation: 90013
This will do it:
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog"),
id = pNode.prev(".modalDialog").attr("id") ||
$('.modalDialog').last().attr("id");;
window.location.href = "#" + id;
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog"),
id = pNode.next(".modalDialog").attr("id") ||
$('.modalDialog').first().attr("id");
window.location.href = "#" + id;
});
});
Fiddle. If no next, it takes first. If no prev, it takes last.
Upvotes: 3
Reputation: 556
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.prev(".modalDialog").length > 0){
if(pNode.prev(".modalDialog")){
var id = pNode.prev(".modalDialog").attr("id");
window.location.href = "#" + id;
}
}else{
if(pNode.prev(".modalDialog")){
var id = $(".modalDialog:nth-last-of-type(1)").attr("id");
window.location.href = "#" + id;
}
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.next(".modalDialog").length > 0){
if(pNode.next(".modalDialog")){
var id = pNode.next(".modalDialog").attr("id");
window.location.href = "#" + id;
}
}else{
if(pNode.next(".modalDialog")){
var id = $(".modalDialog:nth-of-type(1)").attr("id");
window.location.href = "#" + id;
}
}
});
});
Upvotes: 0