It seems like solving this shouldn't be too challenging, but I'm still learning when it comes to Javascript or JQuery.
HTML:
<p><span id="AddLine1Summary"></span>,</p>
<p><span id="AddLine2Summary"></span>,</p>
<p><span id="TownCitySummary"></span>,</p>
<p><span id="CountySummary"></span>,</p>
<p><span id="PostcodeSummary"></span></p>
Even when the Address Line 2 field is left blank, a value of ","
remains. This results in the summary page displaying:
12 Bob Street,
,
BOLTON,
Lancashire,
BL1 1AC
I am working on removing the line
<p><span id="AddLine2Summary"></span>,</p>
completely when the Address Line 2 is empty. Currently, I have tried the following code:
<script>
$(document).ready(function () {
if ($('#AddLine2Summary:contains(",")').length == 1) {
$("#AddLine2Summary").parent().hide();
}
});
</script>
The use of parent.hide
is necessary to ensure that the entire <p>
element is hidden, not just the <span>
.