marisa1981
02-19-2009, 12:28 PM
Hi,
I am using prototype to toggle some content on my web page. It works fine, but I have multiple divs on my FAQ page which I want to toggle. Does anyone know how I can achieve this without assigning iduvidual id's to each div and duplicating all the javascript? Here is what I have so far:
<script type="text/javascript">
Event.observe(window, 'load', function() {
$('featurebox').hide();
$('featurebox-listen').writeAttribute('src', '../../img/branding/btn-next.gif');
Event.observe('featurebox-listen', 'click', function(){
$('featurebox').toggle();
if($('featurebox').visible()){
$('featurebox-listen').writeAttribute('src', '../../branding/chevron-down.gif');
} else {
$('featurebox-listen').writeAttribute('src', '../../img/branding/btn-next.gif');
}
});
});
</script>
<p><img id="featurebox-listen" alt="toggler"/></p>
<div class="featurebox" id="featurebox">
<ul>
<li><strong>Step 1</strong><br />some content.</li>
<li><strong>Step 2</strong><br />some content.</li>
<li><strong>Step 3</strong><br />some content.</li>
<li><strong>Step 4</strong><br />some content.</li>
<li><strong>Step 5</strong><br />some content.</li>
</ul>
<p>some content</p>
</div>
I am using prototype to toggle some content on my web page. It works fine, but I have multiple divs on my FAQ page which I want to toggle. Does anyone know how I can achieve this without assigning iduvidual id's to each div and duplicating all the javascript? Here is what I have so far:
<script type="text/javascript">
Event.observe(window, 'load', function() {
$('featurebox').hide();
$('featurebox-listen').writeAttribute('src', '../../img/branding/btn-next.gif');
Event.observe('featurebox-listen', 'click', function(){
$('featurebox').toggle();
if($('featurebox').visible()){
$('featurebox-listen').writeAttribute('src', '../../branding/chevron-down.gif');
} else {
$('featurebox-listen').writeAttribute('src', '../../img/branding/btn-next.gif');
}
});
});
</script>
<p><img id="featurebox-listen" alt="toggler"/></p>
<div class="featurebox" id="featurebox">
<ul>
<li><strong>Step 1</strong><br />some content.</li>
<li><strong>Step 2</strong><br />some content.</li>
<li><strong>Step 3</strong><br />some content.</li>
<li><strong>Step 4</strong><br />some content.</li>
<li><strong>Step 5</strong><br />some content.</li>
</ul>
<p>some content</p>
</div>