r00stuff
07-01-2011, 03:31 PM
Hi guys, I have a small script that creates elements with createElement(); and assigns an id to it with a variable concatenated to the id, but when the function is ran again it seems like the previous div that was generated doesn't retain the previous id with the concatenated variable.
This is my code:
<script>
function effect(){
$('#btn-slide' + defectsnumber).click(function() {
$('#table2' + defectsnumber).animate({
height: 'toggle'
}, 2000);
});
}
</script>
<script type='text/javascript' language='JavaScript'>
defectsnumber = 0;
function generatedefects()
{
if (defectsnumber > 9) {
alert('You can not enter more than 10 defect percentages!');
} else {
if (defectsnumber == 0)
{
testdiv2 = document.createElement('div');
testdiv2.id = 'testdiv';
}
defectsnumber = defectsnumber + 1;
testingdiv = document.createElement('div');
testingdiv.id='btn-slide' + defectsnumber;
testingdiv.innerText = 'Click Me ' + defectsnumber;
divTag2 = document.createElement('div');
divTag2.id='table2' + defectsnumber;
divTag2.style.cssText = 'background: white; border: 1px solid black; width: 300px; height: 300px; margin-left: 34px; margin-top: 5px; float: left; display: yes;';
divTag2.appendChild(testingdiv);
testdiv2.appendChild(divTag2);
document.body.appendChild(testdiv2);
}
effect();
}
</script>
Does anyone know why that is happening?
This is my code:
<script>
function effect(){
$('#btn-slide' + defectsnumber).click(function() {
$('#table2' + defectsnumber).animate({
height: 'toggle'
}, 2000);
});
}
</script>
<script type='text/javascript' language='JavaScript'>
defectsnumber = 0;
function generatedefects()
{
if (defectsnumber > 9) {
alert('You can not enter more than 10 defect percentages!');
} else {
if (defectsnumber == 0)
{
testdiv2 = document.createElement('div');
testdiv2.id = 'testdiv';
}
defectsnumber = defectsnumber + 1;
testingdiv = document.createElement('div');
testingdiv.id='btn-slide' + defectsnumber;
testingdiv.innerText = 'Click Me ' + defectsnumber;
divTag2 = document.createElement('div');
divTag2.id='table2' + defectsnumber;
divTag2.style.cssText = 'background: white; border: 1px solid black; width: 300px; height: 300px; margin-left: 34px; margin-top: 5px; float: left; display: yes;';
divTag2.appendChild(testingdiv);
testdiv2.appendChild(divTag2);
document.body.appendChild(testdiv2);
}
effect();
}
</script>
Does anyone know why that is happening?