Reputation: 1393
I am using the code bellow to use Jquery UI slider.
<script>
$(function() {
$( "#slider" ).slider({
value:100,
min: 0,
max: 500,
step: 50,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) );
});
</script>
How is this possible to ad this script dynamicly inside a div by pressing a button?
<div id="addscript"></div>
I want to do this that way coz i am generating the slider and some text boxes dynamic like this way.
Thanks
Upvotes: 0
Views: 32
Reputation: 4117
As hinted at in my comment, you will want something like this, ensure you swap out 'button-id' for whatever ID is assigned to yours.
<script>
$(function() {
$('#button-id').on('click', function() {
attachSlider();
});
function attachSlider() {
$( "#slider" ).slider({
value:100,
min: 0,
max: 500,
step: 50,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) );
}
});
</script>
Upvotes: 1