Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <a id="myButton" href="#">
- click here to get random stuff
- </a>
- <div id="myRandomDiv">
- </div>
- <script type="text/javascript" charset="utf-8">
- var randomStrings = [
- "hello 1",
- "hello 2",
- "hello 3",
- "hello 4",
- "hello 5",
- ];
- var randomDiv = document.getElementById("myRandomDiv");
- document.getElementById("myButton").addEventListener("click", function() {
- randomIndex = Math.ceil((Math.random()*randomStrings.length-1));
- newText = randomStrings[randomIndex];
- randomDiv.innerHTML = newText;
- });
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement