The second parameter to the callback function passed to each () will contain the actual DOM element, not the jQuery wrapper object. You can call the getAttribute () method of an element:
$('#category_sorting_form_save').click(function() { var elements = $("#category_sorting_elements > div"); $.each(elements, function(key, value) { console.info(key, ": ", value); console.info("cat_id: ", value.getAttribute('cat_id')); }); });
Or wrap the element in a jQuery object yourself:
$('#category_sorting_form_save').click(function() { var elements = $("#category_sorting_elements > div"); $.each(elements, function(key, value) { console.info(key, ": ", value); console.info("cat_id: ", $(value).attr('cat_id')); }); });
Or just use $(this) :
$('#category_sorting_form_save').click(function() { var elements = $("#category_sorting_elements > div"); $.each(elements, function() { console.info("cat_id: ", $(this).attr('cat_id')); }); });
Frรฉdรฉric Hamidi Nov 06 '10 at 19:55 2010-11-06 19:55
source share