見出しタグをクリックすると、コンテンツが開く
htmlが以下のようになっていれば、
(idとクラス名に、同じ名前にしておけば、)
<h2 id="content1">content1</h2> <div class="content1">content2</h2> <h2 id="content2">content1</h2> <div class="content2">content2</h2>
以下のjQueryで、
$('div[class^="content"]').hide();//css display:noneでもいい。 $("h2").click(function(){ var target ="."+$(this).attr("id"); $(target).toggle("slow"); }); }
見出しクリックで本文が閉じたり開いたりする。
私にも理解できそうなjQuery。
※ なぜ、googleガジェットなのか 等 あたりがサンプルです。