views:

122

answers:

2

I'm currently adding a div to use as a slider programatically, but when I apply the slider to it, everything appears but I can't drag the handle nor do any of the hover states work correctly.

var container = $('<div class="container"></div>');
var slider_div = $('<div class="position_slider"></div>');

$(slider_div).slider();

container.append(slider_div);
$placeholder = $("#"+player_id);
$placeholder.append(container);

I've tried all number of combinations of adding the slider div to no avail, and I'm just wondering if there's something I don't know about that I've missed. Physically adding a <div class="position_slider"> to the page gets the slider working, but that's not an option.

Any help would be appreciated.

A: 

I think this will clear up what this should look like:

var container = '<div class="container"></div>';
var slider_div = '<div class="position_slider"></div>';

$("#"+player_id).append(container);
$(".container").append(slider_div);
$(".position_slider").slider();

I realise that you might want to create many sliders per page, hence the programmatic access, and for that I'd change the class references to ID references and use some kind of counter to create incremental IDs for the controls. I'll leave the actual implementation as an exercise for you.

Lazarus
Yea, you'll have to excuse the messyness, like I say I've been tinkering a lot so it's all a bit out of place. There's also actually a lot more going on in the container, I've just removed it for this example.So you're saying the sliders should all have unique IDs to work properly?
Wil
I think we'd have to see more of the code to be able to know for definite but I try to reserve classes for common visual adornments rather than use as control references. For me controls have specific purposes and as such need specific IDs.
Lazarus
The controls are all working fine, they're identified by their parent. It's this slider that's causing me headaches. I'll get a simpler example together and post it up.
Wil
Solved it - the problem was with another plugin, it was causing mischief, plugin removed - slider working. Good times. Thanks for the help Lazarus.
Wil
@Wil, post the details of your answer as an answer to this question and accept it to close the loop and help those looking for a similar answer in the future.
Lazarus
+1  A: 

The problem was to do with jquery.flash altering the container DIV after the slider had been instantiated. I simply changed the order from build slider, append to container, insert flash to build slider, insert flash, append slider.

If you're having trouble whereby you can see the slider and all the ui components, but you can't operate it, try just removing all other jquery from the page apart from that which you need to accomplish the slider, then add it all back in one by one until you discover the gremlin.

Wil