call jquery function dynamically

call jquery function dynamically

I'm working on a page where I'd like to have multiple accordions or datepickers. I understand that I can add the following code multiple times to my page and change the selector to the ID of the item I want to work with.
  1. <script>
  2.     $(function() {
  3.         $( "#accordion" ).accordion({
  4.             collapsible: true,
  5.             active: false
  6.         });
  7.     });
  8. </script>

    What I would like to do, and what seems more natural to me, is I would like have that code only once with a variable for the id that I can pass in with all the different items I want to work on. It seems because of the way the function/selector works, I can't make it function more generically since there isn't really a call such as "onclick" on the div itself.

Is there anyway to simplify the function so i don't have to have 30 of them if I want say, 30 accordions on my page?

Thanks in advance,
D