Reputation: 3
I want to show an default item when a page loads with this script. At the moment it is only possible when someone clicks on the 'newboxes' items.
function showonlyone(thechosenone) {
var newboxes = document.getElementsByTagName("div");
for(var x=0; x<newboxes.length; x++) {
name = newboxes[x].getAttribute("class");
if (name == 'newboxes') {
if (newboxes[x].id == thechosenone) {
newboxes[x].style.display = 'block';
}
else {
newboxes[x].style.display = 'none';
}
}
}
}
<a href="javascript:showonlyone('newboxes1')">Te reserveren</a> |
<a href="javascript:showonlyone('newboxes2')">Bestbeoordeeld</a> |
<a href="javascript:showonlyone('newboxes3')">Nieuw verschenen</a>
Thanks! :)
Upvotes: 0
Views: 95
Reputation: 3122
Attach it to the onLoad event <body onload="showonlyone('newboxes1')">
Upvotes: 2