moses toh
moses toh

Reputation: 13192

How can I check element have class or not in jQuery validate?

On the highlight, I try like this :

unhighlight: function (element, errorClass, validClass) {
  if(element.prop("class") == "test") 
    document.getElementById('error-message-test').style.display = 'none';
}

There exist error :

element.prop is not a function

How can I solve this error?

Upvotes: 1

Views: 1788

Answers (2)

Mamun
Mamun

Reputation: 68933

You can use jQuery to wrap your element or with hasClass like:

if($(element).prop("class") == "test")

Or

if($(element).hasClass("test"))

Upvotes: 3

Yahya Mukhtar
Yahya Mukhtar

Reputation: 474

You can use hasClass method of jQuery if an element has class or not.

General syntax

if($(element).hasClass('className'))

Based on your scenario

if($(element).hasClass('test'))

Upvotes: 1

Related Questions