The task is this: you need to get all the text fields from the form element and change the value the specific element, say the third.

 $('.reg:text'); // получи доступ ко всем элементам text из класса reg 

    1 answer 1

    Brute force:

     $('yourForm').children('input:text').each(function (index) { //перебор всех элементов if (index == 2) { //третий элемент, так как у первого index==0 //исполняем, например: $(this).val('newVal'); //назначили новый value третьему элементу } }); 

    Instant access:

     $('yourForm').children('input:text').eq(2).val('newVal'); //исполняем. Назначили новый value третьему элементу. 
    • I can not understand how 1 method works and 2 // 1 $ ('. yourForm'). children ('input: text'). each (function (index, element) {if (index == 0) {element.val ( 'asd');}}); // 2 $ ('. YourForm'). Children ('input: text'). Eq (1) .val ('asd') - DigSil
    • In the first method, the each function is run through all the elements that are in the input: text selection of this form. The parameter index (call it anything) is the ordinal number of the element in the sample array. When we reach the desired (s) index (s), we can do with it what we wanted. The link to the element in this construct is $ (this) In the second case, we simply get the link to the element. Conveniently, when the processed elements are few. I will add an example of use now. - knes
    • Can't I do something wrong? $ ('. yourForm'). children ('input: text'). each (function (index) {if (index == 0) {$ (this) .val ('123');}}); - DigSil
    • $ ('. yourForm') // Is there exactly the right selector for the form? - knes
    • The form selector is correct. I don’t understand what the troubles are - DigSil