vendredi 5 février 2016

Random button that reload a div or script not page using jquery or javascript

I'm really new at this and I need a random button on my page that would show a new line of information in a div every time someone click on the random button. I was also wondering if there is over 800 lines is it possible to put it in an outside file as txt or html.

Here is what I got so far and well it doesn't work and I'm getting confuse... Please help

<script type="text/javascript" src="jquery-2.2.0.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#text').hide();

        $('a#random').click(function(){
            $('#text').toggle();
        })

        function RndText() {
            var rannum= Math.floor(Math.random()*textarray.length);
            document.getElementById('#text').innerHTML=textarray[rannum];
        }
        var textarray = [
         "Hello",
         "How are you",
         "Good Bye"    
        ];
        $("#text").load()
    })
</script>

<body>
    <div id="text">Line to Show</div>
    <a href="#" id="random">RANDOM</a>
</body>




Aucun commentaire:

Enregistrer un commentaire