HTML and Javascript - How do we make an onclick button for a random list item? | SoloLearn: Learn to code for FREE!


HTML and Javascript - How do we make an onclick button for a random list item?

I'd like to make a random button like this: The only difference is that I'd like it to display a random HTML list item instead of a random string in the array. What I have down so far: I think it's necessary to associate the collection of <li> with items in a JavaScript array. I've struggled much on aggregating this concept and that of random selection into code.

9/29/2020 8:16:01 AM


6 Answers

New Answer


something like this? you can use object.


I edited the code to show you how you can do that. If you want to add more items like performed by and other then add more properties to object in array.


You don't have to worry about that. Just write your css and when you dynamically add tag to your HTML it will be applied. I again edited the code and added css demo. P.s. level 17 does not have to do anything with skills. :)


RDC WOW. Your code is so organized... You're a real master. That's a level 17 for you haha. There's just one problem. It seems like most of the things now have migrated over to Javascript. As for CSS, how are we supposed to apply styling techniques to the texts and headings if none exist in HTML?


Got it. Thank you for ending my month-long struggle. P.s. It must have something to do with your name then... RDC = Real-Deal Coder >=]


RDC How will your JS portion allow us to include various nested tags within the list item? For instance, the <iframe> and <a href> inside the list items? Reference: