Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1043
  • Last Modified:

jquery validation highlight

Hello,

I'm trying to use jquery validation highlight method but I get an error:

highlight: function(element, errorClass) {
     if (element.attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").addClass("error");
  },
  unhighlight: function(element, errorClass) {
     if (element.attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").removeClass("error");
  }


"element.attr is not a function"

Any ideas?

Thanks
0
Mark Steggles
Asked:
Mark Steggles
  • 2
3 Solutions
 
Albert Van HalenCommented:
element is the DOM element.
You have to create a jquery object to use attr method
Use $(element).attr()
0
 
captaincagemenCommented:
Try it like this:
highlight: function(element, errorClass) {
     if ($(element).attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").addClass("error");
  },
  unhighlight: function(element, errorClass) {
     if ($(element).attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").removeClass("error");
  }

Open in new window

0
 
Albert Van HalenCommented:
Here's the code
You could also refer to the name attribute of the DOM element directly using element.name
// Using jquery
highlight: function(element, errorClass) {
     if ($(element).attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").addClass("error");
  },
  unhighlight: function(element, errorClass) {
     if ($(element).attr("name") == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").removeClass("error");
  }
 
//using DOM
highlight: function(element, errorClass) {
     if (element.name == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").addClass("error");
  },
  unhighlight: function(element, errorClass) {
     if (element.name == "aupairLanguageList")
        $("#multiSelect-aupairLanguageList-title").removeClass("error");
  }

Open in new window

0
 
Mark StegglesWeb DeveloperAuthor Commented:
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now