It is necessary to find the value of a particular input in a particular block. $("div[data-type-diagnosis]") - returns an array of four elements, each of which has its own nested and non-nested elements. I need in each of these 4 elements to find inputs that contain

var yy = $(".input-yy").val(); var mm = $(".input-mm").val(); var dd = $(".input-dd").val(); var hh = $(".input-hh").val(); var mi = $(".input-mi").val();

There is such code:

 var block = $("div[data-type-diagnosis]"); for (x = 0; x < block.length; x++) { var yy = block[x].find(".input-yy").val(); var mm = block[x].find(".input-mm").val(); var dd = block[x].find(".input-dd").val(); var hh = block[x].find(".input-hh").val(); var mi = block[x].find(".input-mi").val(); } 

In this code, swears that find is not a function. But how can I find in each of these four blocks the values ​​of the elements I need and change them to the values ​​I need?

  • 2
    $(block[x]).find(... or block.eq(x).find(... - block[x] returns DOM element - Igor

1 answer 1

Everything works correctly, you only need to refer to jQuery objects:

 var block = $("div[data-type-diagnosis]"); for (x = 0; x < block.length; x++) { var yy = $(block[x]).find(".input-yy").val(); var mm = $(block[x]).find(".input-mm").val(); var dd = $(block[x]).find(".input-dd").val(); var hh = $(block[x]).find(".input-hh").val(); var mi = $(block[x]).find(".input-mi").val(); }