I have a div, let's call it class="phoneNo". Inside the div there are two links, one to add another div just like it, and another to delete the div itself. I'm trying to create a loop where if there's only 1 of these divs, the "delete" link should hide, and if there are more than 1 of these divs, the "delete" link should show up on all the divs.
So far I came up with this, but no success:
var pCount = $(".phoneNo").length;
$(pCount).each(function(){
if (pCount <= 1) {
$("a.deleteThis").hide();
}
else if (pCount >= 1) {
$("a.deleteThis").show();
}
return true;
});
EDIT (3.21.10):
According to jWhiz's advice below, I reworked what I have. The code is error-free and everything works, except for the hiding/showing of the "Delete" link.
Here's my code (some points are irrelevant to the problem, but may help rework my logic flow):
function checkHide() {
if ($(".phoneNo").length == 1)
$(".deleteThisPhone").hide();
else
$(".deleteThisPhone").show();
}
//adding and deleting phone numbers in popup
$(".addNewPhone").live("click", function(){
clicked = $(this);
grandFather = clicked.parent().parent();
cloneCurr = grandFather.clone(true).find("input").each(function(){
$(this).val("")
}).end().animate({opacity:"show"})
grandFather.after(cloneCurr)
checkHide();
newHeight = $("#fancybox-wrap").height();
$('#fancybox-wrap').css({"height": newHeight + 66 + "px" });
return false
});
$(".deleteThisPhone").live("click",function(){
$(this).parent().parent().slideUp(150);
newHeight = $("#fancybox-wrap").height();
$('#fancybox-wrap').css({"height": newHeight - 66 + "px" });
checkHide();
});