//extract reusable code
function operateOptions(el,correspondsTo){
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
$(correspondsTo).append(listItem);//chain methods
listItem.append(imageElement).appendTo(correspondsTo);
}
//create function that accepts multiple options
function redundantSee(list) {
//loop through each option
$.each(list, function(optionSet, correspondsTo) {
//operate on each option in the optionSet
$(optionSet).find('.options').each(function(i,el) {
//i'dsend avoidover usingthe "this"option element and it's corresponding selector
operateOptions(el, correspondsTo);
});
});
}
redundantSee({'.wrapper:eq(0)': 'div.corresponding1', '.wrapper:eq(1)': 'div.corresponding2'});
Here's a pretty-printed, cleaned version:
function operateOptions(el, correspondsTo) {
var self = $(el),
//instead input = self.find('input'), id = input.eachattr('id'),
provides the element as the second argument value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem operateOptions= $(el'<li/>',correspondsTo {
'value': value,
'id': id
});,
imageElement = $('<img/>', {
'src': source,
'title': title
});
}listItem.append(imageElement).appendTo(correspondsTo);
}
//usefunction theredundantSee(list) {
$.each(list, function on(optionSet, thecorrespondsTo) following{
selectors and it's corresponding selectors $(optionSet).find('.options').each(function (i, el) {
redundantSee operateOptions([el, correspondsTo);
});
});
}
redundantSee({'.wrapper:eq(0)': 'div.corresponding1', '.wrapper:eq(1)': 'div.corresponding2'
]});
//extract reusable code
function operateOptions(el,correspondsTo){
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
$(correspondsTo).append(listItem);
listItem.append(imageElement);
}
function redundantSee(list) {
//loop through each
$.each(list, function(optionSet, correspondsTo) {
//operate on each
$(optionSet).find('.options').each(function(i,el) {
//i'd avoid using "this".
//instead, .each() provides the element as the second argument
operateOptions(el,correspondsTo);
});
});
}
//use the function on the following selectors and it's corresponding selectors
redundantSee([
'.wrapper:eq(0)': 'div.corresponding1', '.wrapper:eq(1)': 'div.corresponding2'
]);
//extract reusable code
function operateOptions(el,correspondsTo){
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
//chain methods
listItem.append(imageElement).appendTo(correspondsTo);
}
//create function that accepts multiple options
function redundantSee(list) {
//loop through each option
$.each(list, function(optionSet, correspondsTo) {
//operate on each option in the optionSet
$(optionSet).find('.options').each(function(i,el) {
//send over the option element and it's corresponding selector
operateOptions(el, correspondsTo);
});
});
}
redundantSee({'.wrapper:eq(0)': 'div.corresponding1', '.wrapper:eq(1)': 'div.corresponding2'});
Here's a pretty-printed, cleaned version:
function operateOptions(el, correspondsTo) {
var self = $(el),
input = self.find('input'), id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
listItem.append(imageElement).appendTo(correspondsTo);
}
function redundantSee(list) {
$.each(list, function (optionSet, correspondsTo) {
$(optionSet).find('.options').each(function (i, el) {
operateOptions(el, correspondsTo);
});
});
}
redundantSee({'.wrapper:eq(0)': 'div.corresponding1', '.wrapper:eq(1)': 'div.corresponding2'});
function redundantSee(list) {
//loopextract throughreusable eachcode
$.each(list, function operateOptions(optionSetel,correspondsTo){
//operate on each
$(optionSet).find('.options').each(function(i,el) {
//i'd avoid using "this".
//instead, .each() provides the element as the second argument
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'value' 'id': valueid
}),
imageElement = $('<img/>', {
'id': id
'src': source,
'title': }),title
});
$(correspondsTo).append(listItem);
listItem.append(imageElement =);
}
function $redundantSee('<img/>',list) {
//loop through each
$.each(list, function(optionSet, correspondsTo) {
'src': source,
//operate on each
'title':$(optionSet).find('.options').each(function(i,el) title{
//i'd avoid using "this". });
$(correspondsTo)//instead, .appendeach(listItem); provides the element as the second argument
listItem.appendoperateOptions(imageElementel,correspondsTo);
});
});
}
//use the function on the following selectors and it's corresponding selectors
redundantSee([
'.wrapper:eq(0)': 'div.corresponding1',
'.wrapper:eq(1)': 'div.corresponding2'
]);
function redundantSee(list) {
//loop through each
$.each(list, function(optionSet,correspondsTo){
//operate on each
$(optionSet).find('.options').each(function(i,el) {
//i'd avoid using "this".
//instead, .each() provides the element as the second argument
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
$(correspondsTo).append(listItem);
listItem.append(imageElement);
});
});
}
//use the function on the following selectors and it's corresponding selectors
redundantSee([
'.wrapper:eq(0)': 'div.corresponding1',
'.wrapper:eq(1)': 'div.corresponding2'
]);
//extract reusable code
function operateOptions(el,correspondsTo){
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
$(correspondsTo).append(listItem);
listItem.append(imageElement);
}
function redundantSee(list) {
//loop through each
$.each(list, function(optionSet, correspondsTo) {
//operate on each
$(optionSet).find('.options').each(function(i,el) {
//i'd avoid using "this".
//instead, .each() provides the element as the second argument
operateOptions(el,correspondsTo);
});
});
}
//use the function on the following selectors and it's corresponding selectors
redundantSee([
'.wrapper:eq(0)': 'div.corresponding1',
'.wrapper:eq(1)': 'div.corresponding2'
]);
Pretty much explained in the comments
function redundantSee(list) {
//loop through each
$.each(list, function(optionSet, correspondsTo) {
//operate on each
$(optionSet).find('.options').each(function(i,el) {
//i'd avoid using "this".
//instead, .each() provides the element as the second argument
var self = $(el),
input = self.find('input'),
id = input.attr('id'),
value = input.val(),
title = self.find('.title').text(),
source = self.find('img').attr('src'),
listItem = $('<li/>', {
'value': value,
'id': id
}),
imageElement = $('<img/>', {
'src': source,
'title': title
});
$(correspondsTo).append(listItem);
listItem.append(imageElement);
});
});
}
//use the function on the following selectors and it's corresponding selectors
redundantSee([
'.wrapper:eq(0)': 'div.corresponding1',
'.wrapper:eq(1)': 'div.corresponding2'
]);
default