Forum: Ruby on Rails Element.toggle with multiple divs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Afebfc47e8dfbecb51319218ec29bc41?d=identicon&s=25 patrick (Guest)
on 2005-11-13 15:56
(Received via mailing list)
i have a number of div's on my site with "id_distributor_1" to
"id_distributor_x" (x depends on the number of entries in the database).
now i´d like to toggle these divs. with using element.toggle i have to
know
the id-names, which is not the case because i don´t know how many
entries
there are.

any suggestions?
00e3a96684ab390a350b0271e98741d3?d=identicon&s=25 Nshbrown Nshbrown (nshb)
on 2005-11-13 15:56
(Received via mailing list)
Untested, but you could do something like this...

<script>
function toggleDisplay()
    for (var x = 0; ; x++) {
      	if (var element = document.getElementById('id_distributor_' + x))
{
			element.style.display = 'none';
		} else {
			return;
		}
	}
}
</script>

Warmest regards,
Nathan.
This topic is locked and can not be replied to.