jQuery: How to remove this code redundancy?
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-04-11T20:24:02Z
Indexed on
2010/04/11
20:33 UTC
Read the original article
Hit count: 216
JavaScript
|jQuery
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?
© Stack Overflow or respective owner