Reputation: 633
I am trying to validate some elements that are dynamically generated with jquery.
here is the code I have
$newInsert = $("#aconditional").clone();
$test = $newInsert.find("[name='trailvalue']");
$test.rules("add",{
required: true
});
trailvalue is just an element inside the generated div.
when I run javascript with this I get a javascript error "$test.rules is not a function"
I have validation working inside other parts of the same html file, so I sure I am including the validation plugin correctly.
anyone see something I dont see ?
I tried this as well for testing purposes
$("[name='trailvalue']").each(function (index,element){
$(this).rules("add",{
required:true
});
});
got a slight different error "a is null"
thank you
Upvotes: 1
Views: 940
Reputation: 72961
clone
doesn't copy events by default. Therefore the rules()
events are not cloned and ultimately not bound to $test
. Check out the docs - http://api.jquery.com/clone/ and try the following:
$newInsert = $("#aconditional").clone(true);
Upvotes: 1