Your code makes very little sense as you've posted it...
if ($(this).attr("san") != "") {
jQuery.validator.addClassRules("san" , { required: true });
$.validator.addMethod("san", function() {
required: true
}, "Please enter your name");
}
else if ($(this).attr("san") == "") {
jQuery.validator.removeClassRules("san");
}
$(this)
does not represent anything in the context of your code.
There is no such thing as removeClassRules()
in the jQuery Validate plugin.
You're using the .addMethod()
method improperly. This method is for creating new rules (methods) from scratch. You must only put valid jQuery/JavaScript inside the function(){}
. required: true;
inside of a function(){}
is totally meaningless, and a syntax error.
You're assigning the required
rule to a class
called san
using addClassRules()
. This seems unnecessary. The whole purpose of the addClassRules()
method is to combine multiple standard rules into one (called a compound rule) and assign that compound rule to a class
. Then the rules can be applied to input elements simply by using the class
.
You're trying to add a method called san
, create a class
rule called san
, while you have an attribute
called san
. Again, none of this makes any sense.
Quote OP:
"how we use addclassrules and removeclassrules in jquery plugin . with an examples."
You start by reading the documentation and looking at the posted examples. As you can see, there is no such thing as a removeclassrules
method.
Then when asking a question here, you would clearly describe what you want it to do, what's going wrong, and include enough code for a self-contained example, including the relevant HTML markup.
See: How to create a Minimal, Complete, and Verifiable example
.removeClassRules()
method, so that would be one issue. – Sparky Jul 1 at 15:09