I need to find all the elements with the class incorrect , when I have this object of one of the input in the table (no matter what), then I have to run through and count the number of these fields, if the text is unique, I delete the class.

I have a typeahead class for all selections typeahead

 function ValidProduct(Obj,Metka){ var Input = $(Obj); console.log("--",Input.closest('tbody').find('input.typeahead.incorrect').length); Input.closest('tbody').find('input.typeahead.incorrect').each(function(){ console.log(this); }); } 

And it turns out that this function object is not taken into account in the traversal. What's wrong?

  • try console.log ($ (this)); - Arsen
  • the point is not in the output but in the fact that it skips the object that was passed to the function. - Oma
  • It is necessary to lay out the html-code c table - Crantisz
  • It is not clear why you need such a strict selection. There may be a sea of ​​options. First, execute $ ('input.typeahead.incorrect') in the console. Each (function () {console.log (this);}); - Kostiantyn Okhotnyk
  • one
    What does this function object mean not be counted in the traversal ? - Grundy

1 answer 1

$.each takes 2 arguments. The first as an index, and the second as a value itself (in this case, an object):

 function ValidProduct(Obj, Metka) { var Input = $(Obj); console.log("--", Input .closest('tbody') .find('input.typeahead.incorrect') .length); Input .closest('tbody') .find('input.typeahead.incorrect') .each(function (index, object) { console.log(object); }); } 
  • 2
    the second parameter has the same value as this in this case - Grundy