Hi,

I am looking to use jQuery in conjunction with xVal for validation.
One of the cool things I though jQuery would allow me to do is append
an asterisk (*) to the label of "ALL" my fields that have a css class
of "required". The example below only applies the asterisk to the
first field.

How can I get all of the fields from my page that have a
class="required", find the label (previous element) for each, and
append some text (an asterisk) to the label for that field?

Example
======================

<script type="text/javascript">
$(document).ready(function() {
           //$('label.required').append('&nbsp;<strong>*</
strong>&nbsp;');
           $(".required").each().prev().not('input').not('br').not
('select').append(' * ');
       });
</script>

<label for="FirstName'>LastName</label>
<input id="FirstName" class="required" />

<label for="LastName">LastName</label>
<input id="LastName" class="required" />

Thanks,

Baum

Reply via email to