Forum Moderators: open
If instead of having a fixed number of divs as in your list of names, what if I had an unknown number of items in the list and I wanted to create as many headings, plus/minus gifs, and div content for each if they existed?
How would I code for that?
Thanks in advance,
Tony
But on this page, I do not know how many schools will be available for a given location. I was thinking I would like to be able to click on the school and have more detail available in the div that becomes visible. This would be as apposed to having the school be a link that goes to a detail page.
Birdbrain provided this script for show/hide divs. What I can not figure out is how to create the divs dynamically.
[webmasterworld.com...]
[edited by: encyclo at 11:04 pm (utc) on Mar. 25, 2007]
[edit reason] no URLs please, see TOS [webmasterworld.com] [/edit]
how to create the divs dynamically
With JavaScript, this can be done using two DOM methods: document.createElement()
[developer.mozilla.org] and element.appendChild()
[developer.mozilla.org].
<script type="text/javascript">
var newDiv = document.createElement('div');
newDiv.innerHTML = 'school information here';
document.getElementById('parentElement').appendChild(newDiv);
</script>