Hey, I don’t have any code because I don’t know how to do this. I’m looking to use jQuery / javascript to randomly append the CSS class “active” to one list item within a an unordered list id’d as ul#sliding_panels.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Keep it simple. This retrieves all the list items under that list:
Then use
Math.random()to pick one of them. Note: the constructMath.floor(Math.random() * 10))will return an integer between 0 and 9 inclusive.You can use the array index operator on a jQuery object to retrieve one of those elements. Note:
set[n]is equivalent toset.get(n)ifsetis a jQuery object.You then need to wrap that element in a jQuery object and use
addClass():