Just_Vee Posted June 11, 2020 Share Posted June 11, 2020 Site URL: https://www.slowmyroll.com/ Does anyone know how to create a button that each time it's clicked, will take you to a random quote? I'm trying to create a series of quotes that people can randomly be given when they click the button. Link to comment
tuanphan Posted June 12, 2020 Share Posted June 12, 2020 Add to Code Block <section id="background"> <div id="quote-container"> <h1 id="quote-container-heading">Step Brother Quotes</h1> <p id="quote"> Keep you liver spotted hands off my mother shes a saint </p> <h5 id="author">-Dale</h5> <a class="button">New Quote</a> </div> </section> <style> #background { height: 100vh; background-repeat: no-repeat; background-size: cover; color: #000; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; } #background p { font-size: 24px; } </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script> <script> $(document).ready(function() { var quotes = ["Thanks for the job you did", "Made my website look awesome online", "Took my business online"]; var author = ["-Customer 1", "-Customer 2", "-Customer 3"]; $('.button').click(function() { randomNum = Math.floor(Math.random() * quotes.length); $("#quote").text(quotes[randomNum]); $("#author").text(author[randomNum]); }); }); </script> Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.