- Joined
- Dec 27, 2008
- Messages
- 587 (0.10/day)
System Name | PC |
---|---|
Processor | i5 2500k |
Motherboard | P8Z68-V PRO/GEN3 |
Cooling | Fans |
Memory | DDR3-1600 (8GB) |
Video Card(s) | Sapphire Nitro+ RX 580 |
Storage | HD103SJ |
Display(s) | XG2402 |
Case | Xigmatek Midgard II |
Power Supply | PC Power & Cooling Silencer 750W |
Hi all.
I have four <div> elements and I'm trying to use Javascript to display one of the four (the rest would be hidden).
I have the HTML/CSS in place, it's the Javascript that's giving me trouble.
<div id="numberOne">
<div id="numberTwo">
<div id="numberThree">
<div id="numberFour">
I need the Javascript that will randomly select one of these divs and display it.
This is what I have so far. I could be way off.
I have four <div> elements and I'm trying to use Javascript to display one of the four (the rest would be hidden).
I have the HTML/CSS in place, it's the Javascript that's giving me trouble.
<div id="numberOne">
<div id="numberTwo">
<div id="numberThree">
<div id="numberFour">
I need the Javascript that will randomly select one of these divs and display it.
This is what I have so far. I could be way off.
Code:
<script>
var array = [];
var selectedValue = Math.floor(Math.random() * array.length);
var selectedDiv = document.getElementById(selectedValue);
selectedDiv.style.display = "block";
</script>