1

Any idea why this won't work? What I'm trying to do is add some div tags dynamically and then apply them with a slider.

    $(function () {

        var testarea =  $('<div id="testarea" />');

        for (var i = 0; i < 3; i++) {
            $('<div class="testslider"></div>').appendTo(testarea);
        }

        $('#somearea').html(testarea.html());

        $(".testslider").slider({
            value: 100,
            min: 0,
            max: 500,
            step: 100,
            slide: function (event, ui) {
            }
        });
   });

html:

<div id="somearea"></div>

If I just add the div tags normally like so then its ok so I'm not too sure how to apply it dynamically.

fes
  • 2,465
  • 11
  • 40
  • 56

1 Answers1

2

May as well just do it in one go anyway

$(function () {
    for (var i = 0; i < 3; i++) {
        $('<div class="testslider"/>').slider({
            value: 100,
            min: 0,
            max: 500,
            step: 100,
            slide: function (event, ui) {
            }
        }).appendTo('#testarea');
    }
});
Popnoodles
  • 28,090
  • 2
  • 45
  • 53