jQuery: How to remove this code redundancy?
- by Mark
clone.find('[id]').each(function() {
id = $(this).attr('id');
ind = id.search(/\d+$/);
$(this).attr('id', id.substr(0,ind)+id_counter);
});
clone.find('[for]').each(function() {
id = $(this).attr('for');
ind = id.search(/\d+$/);
$(this).attr('for', id.substr(0,ind)+id_counter);
});
I know I can find elements that have either the id attribute or the for attribute, but then how do I know which one I need to set?