Niklas Richter: jQuery: Dynamische Funktion aus Snippet machen

Beitrag lesen

Hallo,

ich möchte diese jQuery-Funktion benutzen:

$(document).ready(function(){  
	  
$("a#animate").click().toggle(function(){$(this).next().animate({Height:'hide',opacity:'hide'},'slow');},function(){$(this).next().animate({Height:'show',opacity:'show'},'slow');});  
	  
});

HTML:

  
<div><a href="#" id="animate">open/close</a></div>  
<div id="block1" style="background:yellow;height:500px">Test</div>  
  
<div><a href="#" id="animate">open/close</a></div>  
<div id="block2" style="background:yellow;height:500px">Test</div>  
  
<div><a href="#" id="animate">open/close</a></div>  
<div id="block3" style="background:yellow;height:500px">Test</div>  
  
usw.

Wie kann ich jetzt obigen jQuery abändern, damit er nicht das nächste Element nimmt, sondern konkret eine ID? Und wie übergebe ich die an die jQuery-Funktion?

Ich meine etwa sowas:

  
function toggler(id)  
{...}

Danke!
Niklas