Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery filter() to get all matched .val()

I have a number of textfields and I need to select the values of those textfields whose values are not equal to their title attribute.

Problem: With my attempt, the jQuery code below simply selects the value of the first matched textfield. How do I get all matched textfields' values?

jQuery Code

var inputs = $(".input").filter(function() {
                return $(this).val() != $(this).attr('title');
            }).val();
console.log(inputs);
like image 932
Nyxynyx Avatar asked Dec 16 '22 04:12

Nyxynyx


1 Answers

Here is simpler solution:

var input = [];
jQuery('input[type=text]').each(function(){
   if(jQuery(this).val() != jQuery(this).attr('title') ) {
   input.push(jQuery(this).val());
   }
});
like image 135
Nurlan Avatar answered Dec 18 '22 19:12

Nurlan