Snažím se použít jQuery k procházení seznamu prvků, které mají stejný název třídy, a extrahovat jejich hodnoty.
Mám tohle..
function calculate() { // Fix jQuery conflicts jQuery.noConflict(); jQuery(document).ready(function(){ // Get all items with the calculate className var items = jQuery('.calculate'); }); }
Četl jsem o funkci every(), i když jsem byl zmatený, jak ji v tomto případě správně použít.
Odpověď
jQuery('.calculate').each(function() { var currentElement = $(this); var value = currentElement.val(); // if it is an input/select/textarea field // TODO: do something with the value });
a pokud byste chtěli získat jeho index do kolekce:
jQuery('.calculate').each(function(index, currentElement) { ... });
Reference:.each()
a .val()
funkce.