I have this jQuery function that appends a span labelled “optional” to a label if no option is set in the select box.
function setLabel() {
var label=$('label[for=person_address]');
if ($('select#person_organisation_id').val().length != 0) {
label.append(' <span>— optional</span>');
} else {
label.children().remove();
}
}
Right now this adds a new span to the label every time I select a new option. How can I check if a span already exists and only add a span if there is none already?
Thanks for any help…
Try the following: