Help with simple javascript loop
- by Gabriel
Hello,
I have a simple javascript that I'd like to loop for multiple elements. Here's my code:
<script type='text/javascript'>
for(i = 1; i < 100; i++)
{
$('#link'+i).click(function() {
$('#container').removeClass();
$('#container').addClass('templateid'+i);
});
}
</script>
What I'd like to achieve is the same addClass function for multiple id's (e.g. link2, link3, link4), with the corresponding class (e.g. template2, template3, template4).
Any help would be hugely appreciated!
For reference, an individual call like this one, does work, so I don't see why the loop above doesn't function the same:
<script type='text/javascript'>
$('#link2').click(function() {
$('#container').removeClass();
$('#container').addClass('templateid2');
});
</script>