Reputation: 11000
Im assembling a form validation script and Im pretty stuck on this:
$("*").live('click', function(){
if($(".validate").val()=="")
{
$(this).addClass("partError");
}
});
The first selector is attached to everything so that it is constantly updating, but when the function runs it won't do anything.
I want this function to only select the input
belonging to this class that are empty. But there can be a variable number of these elements belonging to the .validate
class.
Upvotes: 0
Views: 65
Reputation: 2727
try :
$("html").live('click', function(){
if($(".validate").val()=="")
{
$(this).addClass("partError");
}
});
Upvotes: 0
Reputation: 96944
Why are you attaching it to everything?
$(".validate").live('click', function(){
if($(this).val() == "")
{
$(this).addClass("partError");
}
});
Upvotes: 2