I am working on a maintenance site which will handle job logging etc. In the administration section, there is a list of Active and Completed jobs in a list.
As it stands, i have a jQuery function for each job which has been logged to show/hide a description of each job.
There are only 5 jobs per page currently, but would like to extend this to possible up to a max of 50 jobs per page through use of a drop down menu.
This is all good and well until you get to the jQuery side of things, where you would need to specify 50 individual pairs of statements for hiding/showing descriptions.
I realize i could probably just do a simple for loop inside the printing of the jQuery at the top of the page:
Code: Select all
for($i=0; $i<=$_GET['numJobs']; $i++){
print "$('.paragraph{$i}:visible').removeAttr('style').hide().fadeOut();
$('input.show_post{$i}').click(function(){ $('div.contentToChange').find('div.paragraph{$i}:hidden').slideDown('slow'); });
$('input.hide_post{$i}').click(function(){ $('div.contentToChange').find('div.paragraph{$i}:visible').slideUp('slow'); });
";
}I realize its probably the worst possible way of going about doing it, but it is the only way that i can think of cleaning up the source code of a page.
If anyone has an alternative or just thinks the idea is stupid and i should just leave the 100+ lines of jQuery at the top of each page, the just say so
Or would i be better off pre-generating each of the statements in an external .js file for each of the 50 job sets and just not worry about dynamically generating the code?