This should work, at least the logic is transposed: $('.fieldpair').each(function(){ var self = $(this); if (self.find('input:checked').length){ total += +self.find('input:text').val(); } });
On Sep 1, 10:08 am, Jermaine <jermaine2...@gmail.com> wrote: > Hi All, > > I want to refactor (port) the following PrototypeJS code to jQuery. > I'm in the process of learning jQuery and currently stuck with porting > this piece of code... Any idea's? > > [code] > var total = 0; > > // For each fieldpair that has a child with a checked input > // we get the sibling with a text input and add that value > // to the total. > $$(".fieldpair").each(function(fieldpair) { > if (fieldpair.down("input:checked")) { > var input = fieldpair.down('input:text'); > total += parseInt(input.value); > }}); > > [/code]