I have a scenario where I have a code like this
HTML
<input type="submit" value="" name="submit" id="slider1">
SCRIPT
$(document).ready(function() {
$("#slider1").Slider();
});
when document loads, some stuff is done to my input box by my Slider() function.
The issue am facing is that, am replacing the same input box html on ajax return and can't get my Slider() called.
AJAX RETURN
...
success: function(data) {
// This was removing the wrapper element, all the other calls
// to $('#slider1') were doing nothing
//$("#slider1").remove();
$("#slider1").html('<input type="submit" value="{{ some variable }}" name="submit" id="slider1">');
}
...
I was thinking of calling the Slider() function inside the input box so that it will be called,
something like:
$("#slider1").html('<input type="submit" callSliderFunction="Slider()" value="{{ some variable }}" name="submit" id="slider1">');
Is it possible to call it there? If not How can I achieve this? Thanks
3 Answers 3
I would just call .Slider() again after you add it to the page in the success function.
success: function(data) {
$("#slider1").remove();
$("#slider1").html('<input type="submit" value="{{ some variable }}" name="submit" id="slider1">');
$("#slider1").Slider();
}
As Juan pointed out, you can't call .html() on #slider1 once you .remove() it. From looking at what you have, its my guess that you're trying to change the value of the #slider1, in which case it would be simpler to do just that
success: function(data) {
$("#slider1").attr("value", "{{ some variable }}");
$("#slider1").Slider();
}
5 Comments
$("#slider1").remove() will remove #slider1,I don't think you should do thatremove(), there will be no more #slider1 and the functions won't do anythingJust call it after you've setup the HTML
success: function(data) {
var wrapper = $("#slider1");
wrapper.html('<input type="submit" value="{{ some variable }}" name="submit" id="slider1">');
wrapper.Slider();
}
Comments
Just call it like you did when the document loaded after you have changed the html.
$("#slider1").Slider();
1 Comment
$('#slider1').Slider(); $.html will return the new content, the input tag.
submitwith idslider1and onajax successyou have remove element whose idslider1and again you have added some code...$("#slider1").html("your html"). Just think about what have you done. Can you really do this ??$(input).html(). Can you please explain me little bit?