Reputation: 118
I'm trying to put variable into name of class and after hours of searching I haven't found answer.
This is my code. I want to put var i
to class red_val
to have red_val1
and then red_val2
etc.
If anyone could help me that would be great!
$(document).ready(function () {
var i = 1;
$('.container').on('click', '.dodaj', function () {
i++;
$('<div id="red_val"[+i]>ss</div><div id=red></div><div id=green></div><div id=blue></div>').appendTo('.container');
});
});
Upvotes: 1
Views: 30
Reputation: 11502
Try this:
$(document).ready(function () {
var i = 1;
$('.container').on('click', '.dodaj', function () {
$('<div id="red_val'+i+'">ss</div><div id="red'+i+'"></div><div id="green'+i+'"></div><div id="blue'+i+'"></div>').appendTo('.container');
$( "#red"+i, "#green"+i, "#blue"+i ).slider({ orientation: "horizontal", range: "min", max: 255, value: 127, slide: refreshSwatch, change: refreshSwatch });
i++;
});
});
Upvotes: 1