I have an address search system in which the user enters a zip code, if the zip code is checked, then an address list is returned and an address bar is selected, the list disappears, and then the address bar is further divided into some form of inputs.
The problem I encountered is when they went through the above process, then cleared the zip code form field, click the address search button and the address list will reappear.
An event, although the list and parent tr were removed from the DOM, does it still report that it is present as length 1?
My code is as follows:
JQuery
var $addressList = $("div#selectAddress > ul").length;
if ($addressList != 0) {
$("div#selectAddress").closest("tr").removeClass("hide");
}
var $customerAddress = $("form#detailsForm input[name*='customerAddress']");
var $addressInputs = $.cookies.get('cpqbAddressInputs');
if ($addressInputs) {
if ($addressInputs == 'visible') {
$($customerAddress).closest("tr").removeClass("hide");
}
} else {
$($customerAddress).closest("tr").addClass("hide");
}
$("input.findAddress").live('click', function(){
var $postCode = encodeURI($("input#customerPostcode").val());
if ($postCode != "") {
var $formAction = "customerAction.do?searchAddress=searchAddress&custpc=" + $postCode;
$("form#detailsForm").attr("action", $formAction);
} else {
alert($addressList);}
});
$("div#selectAddress ul li").live('click', function(){
$(this).removeClass("addressHover");
$(this).addClass("addressClick");
var $splitAddress = $(this).text().split(",");
$($customerAddress).each(function(){
var $inputCount = $(this).index("form#detailsForm input[name*='customerAddress']");
$(this).val($splitAddress[$inputCount]);
});
$($customerAddress).closest("tr").removeClass("hide");
$.cookies.set('cpqbAddressInputs', 'visible');
$(this).closest("tr").fadeOut(250, function() { $(this).remove(); });
});
source
share