Search code examples
jqueryencapsulation

JQuery Encapsulation


I have written a few jquery functions for form validation. It works fine but if I want to have more than one form on a page, it validates all the form elements in all the forms regardless of which one was submitted.

Is there a way to make the jquery execute only for a particular div container that is defined in document ready? Maybe using a class name that is assigned to the container and form validation would only occur inside that container when submitting the form?

Thanx!


Solution

  • Sure, you can do something like $('#mycontainer form').validate(); or whatever your validate functions are. Better yet, you can give your form an id and target it directly.