Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reportValidity() in jquery?

Tags:

jquery

I need to call reportValidity but I want to this in jquery, which is the method that replicated this logic in jquery?

For example:

$('login').submit(function(event) {
  $(this).reportValidity();
}); 

this return:

reportValidity is not a function

like image 557
user3287550 Avatar asked Aug 14 '16 13:08

user3287550


1 Answers

It's because $(this) wraps it in a jQuery object which does not support the method reportValidity(). It must be called on the native DOM element. In your case it would suffice to not wrap it in jQuery, just like

$('login').submit(function(event) {
  this.reportValidity();
}); 

For clarification and adaption, this would work too:

$('login').submit(function(event) {
  var $this = $(this);
  $this.get(0).reportValidity();
}); 

.get retrieves the plain element of a jquery collection.

like image 94
Adrian Föder Avatar answered Nov 19 '22 04:11

Adrian Föder