I have a JQuery / Javascript function that is to be used across my site for some basic UI functionality. However, many of the elements that this function effects, will be injected via Ajax, while others will be static html.
Currenty I've been able to make my scripts work for me by duplicating the function and applying both $(document).ready and $(document).ajaxSucces.
My question is: What is the appropriate accomplishing this?
This is my JS:
$(document).ready(function () {
$(".hidesfieldset:not(:first)").hide();
$("fieldset").bind("focus click",function () {
$(".hidesfieldset:not(:parent)").hide(800);
$(".hidesfieldset", this).slideDown(800);
});
});
$(document).ajaxSuccess(function () {
$(".hidesfieldset:not(:first)").hide();
$("fieldset").bind("focus click",function () {
$(".hidesfieldset:not(:parent)").hide(800);
$(".hidesfieldset", this).slideDown(800);
});
});
Because some of my forms are inject via ajax, the first function is not applied to them, so I also had to include the ajax Success.
Note*: I'm a complete newb when it comes to JS, this is my first time working with it, probably in a little over my head. So if you see other things in this that are wrong, feel free comment.
Thanks, Mark