I\'m stuck with a situation where my DOM elements are generated dynamically based on $.getJSON
and Javascript functions for this elements are not working. I\'ll
Firstly you need to use a delegated event handler to catch events on dynamically appended elements. Then you can call the .slider()
method again within the success handler function to instantiate the plugin on the newly appended content. Try this:
$(document).ready(function(){
$('#parentElement').on('click', '.element', function() {
$(this).toggleClass('active');
});
var sliderOptions = { /* slider options here */ };
$(".slider").slider(sliderOptions);
$.getJSON('json/questions.json', function(data) {
// generating some DOM elements...
$('#parentElement .slider').slider(sliderOptions);
});
});