views:

38

answers:

3

I do something like this:

$(".field-validation-error").addClass('ui-state-error');

and at some moment something like this happens

$("body").prepend("<span class="field-validation-error">This field is required.</span>")

I would like this new added element to have also the class 'ui-state-error'

+5  A: 

You can either add it yourself, changing that .prepend() call, or use the .livequery() plugin, like this:

$(".field-validation-error").livequery(function() {
  $(this).addClass('ui-state-error');
});

this will execute for all bounds .field-validation-error elements, and future ones. Or, if changing the stylesheet is an option, just include both selectors:

.field-validation-error, .ui-state-error { ....styles.... }
Nick Craver
+1 for plugin :)
Fabrizio Calderan
A: 

jQuery Live

NimChimpsky
`.live()` is for handling events, something that doesn't happen here.
Nick Craver
A: 

why dont you just do this:

$("body").prepend("<span class="field-validation-error ui-state-error">This field is required.</span>")
jknair