[jquery] jQuery .each() with input elements

//save tablet
jQuery("#savetablet"+jTablets[i].idtablets).on('click', function()
{
    alert("alertsepy2...");
    console.log(jTablets[i].idtablets);
    jQuery("#tablet"+jTablets[i].idtablets+" .detailsrow").each(function( index ) {
        $(this).each(function( index2 ) {
            console.log($(this).html());
        });
    });
});

<div class="column0"><input type="text" value="-D"></div>
<div class="column1"><input type="text" value="D"></div>
<div class="column2"><input type="text" value="D"></div>
<div class="column3"><input type="number" value="0"></div>
<div class="column4"> <input type="number" value="0"></div>
<div class="column5"> <input type="number" value="0"></div>
<div class="column6"><input type="number" value="0"></div>
<div class="column7"><input type="number" value="0"></div>
<div class="column8"><input type="number" value="0"></div>
<div class="column9"> <input type="number" value="0"></div>
<div class="column10"> <input type="number" value=""></div>
<div id="tablet17row0" class="column11">11</div>
<div class="column0"><input type="text" value="-D"></div>
<div class="column1"><input type="text" value="D"></div>
<div class="column2"><input type="text" value="D"></div>
<div class="column3"><input type="number" value="0"></div>
<div class="column4"> <input type="number" value="0"></div>
<div class="column5"> <input type="number" value="0"></div>
<div class="column6"><input type="number" value="0"></div>
<div class="column7"><input type="number" value="0"></div>
<div class="column8"><input type="number" value="0"></div>
<div class="column9"> <input type="number" value="0"></div>
<div class="column10"> <input type="number" value=""></div>
<div id="tablet17row1" class="column11">21</div>

I have the above jQuery .each() that outputs the attached HTML to the console. In this case I want to extract the val() of only the input elements either of type text or type number. Is there some way to isolate just the input elements so I can get their values out into an array?

Thanks in advance...

This question is related to jquery input each

The answer is


You can use:

$(formId).serializeArray();

$.each($('input[type=number]'),function(){
  alert($(this).val());
});

This will alert the value of input type number fields

Demo is present at http://jsfiddle.net/2dJAN/33/


Assume if all the input elements are inside a form u can refer the below code.

 // get all the inputs into an array.

    var $inputs = $('#myForm :input');

    // not sure if you wanted this, but I thought I'd add it.
    // get an associative array of just the values.
    var values = {};
    $inputs.each(function() {
        values[this.name] = $(this).val();
    });

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to input

Angular 4 - get input value React - clearing an input value after form submit Min and max value of input in angular4 application Disable Button in Angular 2 Angular2 - Input Field To Accept Only Numbers How to validate white spaces/empty spaces? [Angular 2] Can't bind to 'ngModel' since it isn't a known property of 'input' Mask for an Input to allow phone numbers? File upload from <input type="file"> Why does the html input with type "number" allow the letter 'e' to be entered in the field?

Examples related to each

jQuery animated number counter from zero to value How to iterate over array of objects in Handlebars? Excel VBA For Each Worksheet Loop jQuery looping .each() JSON key/value not working jQuery '.each' and attaching '.click' event How to use continue in jQuery each() loop? jQuery .each() with input elements C++ for each, pulling from vector elements jQuery each loop in table row Get href attribute on jQuery